From 7b1ec0ae9603adab926b2da01e00e16646b03aff Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 16 Apr 2014 14:58:40 +0200 Subject: [PATCH] Rename _remove_consecutive_duplicates to _squash_repeats --- doc/ext/notebook.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/doc/ext/notebook.py b/doc/ext/notebook.py index 36c6fa1f..a306f11d 100644 --- a/doc/ext/notebook.py +++ b/doc/ext/notebook.py @@ -30,8 +30,8 @@ sample = """{ }""" -def _remove_consecutive_duplicates(x): - """Remove duplicates of elements appearing consecutively. +def _squash_repeats(x): + """Reduce repeating elements to a single occurrance. Parameters ---------- @@ -40,19 +40,17 @@ def _remove_consecutive_duplicates(x): Returns ------- - modified_x : list - Output list, with no consecutive duplicates. + list + A copy of `x` with repeating elements squashed. Examples -------- >>> input = [1, 2, 3, 3, 4, 5, 6, 6] - >>> output = remove_consecutive_duplicates(input) - >>> output + >>> print _squash_repeats(input) [1, 2, 3, 4, 5, 6] """ - modified_x = [x[0]] + [x[i] for i in range(1, len(x)) if x[i] != x[i-1]] - return modified_x + return [x[0]] + [x[i] for i in range(1, len(x)) if x[i] != x[i-1]] class Notebook(): @@ -146,7 +144,7 @@ def python_to_notebook(example_file, notebook_path): docstring = False source = [] - code = _remove_consecutive_duplicates(nb.code) + code = _squash_repeats(nb.code) for line in code: # A linebreak indicates a segment has ended.