Skip to content

Instantly share code, notes, and snippets.

@lihuanshuai
Last active September 28, 2017 07:23

Revisions

  1. lihuanshuai revised this gist Sep 28, 2017. No changes.
  2. lihuanshuai revised this gist Sep 28, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,5 @@
    def previous_and_next(iterable, fill_value=None):
    prevs, items, nexts = tee(iterable, 3)
    prevs = chain([fill_value], prevs)
    nexts = chain(islice(nexts, 1, None), [fill_value])
    return izip(prevs, items, nexts)
    nexts = chain(slice(nexts, 1, None), [fill_value])
    return zip(prevs, items, nexts)
  3. lihuanshuai revised this gist Sep 28, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    from itertools import tee, islice as slice, chain, izip as zip

    def previous_and_next(some_iterable, fill_value=None):
    prevs, items, nexts = tee(some_iterable, 3)
    def previous_and_next(iterable, fill_value=None):
    prevs, items, nexts = tee(iterable, 3)
    prevs = chain([fill_value], prevs)
    nexts = chain(islice(nexts, 1, None), [fillvalue])
    nexts = chain(islice(nexts, 1, None), [fill_value])
    return izip(prevs, items, nexts)
  4. lihuanshuai revised this gist Sep 28, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    from itertools import tee, islice as slice, chain, izip as zip

    def previous_and_next(some_iterable, fillvalue=None):
    def previous_and_next(some_iterable, fill_value=None):
    prevs, items, nexts = tee(some_iterable, 3)
    prevs = chain([fillvalue], prevs)
    nexts = chain(islice(nexts, 1, None), [None])
    prevs = chain([fill_value], prevs)
    nexts = chain(islice(nexts, 1, None), [fillvalue])
    return izip(prevs, items, nexts)
  5. lihuanshuai revised this gist Sep 28, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    from itertools import tee, islice as slice, chain, izip as zip

    def previous_and_next(some_iterable, fillval):
    def previous_and_next(some_iterable, fillvalue=None):
    prevs, items, nexts = tee(some_iterable, 3)
    prevs = chain([None], prevs)
    prevs = chain([fillvalue], prevs)
    nexts = chain(islice(nexts, 1, None), [None])
    return izip(prevs, items, nexts)
  6. lihuanshuai revised this gist Sep 28, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    from itertools import tee, islice as , chain, izip
    from itertools import tee, islice as slice, chain, izip as zip

    def previous_and_next(some_iterable):
    def previous_and_next(some_iterable, fillval):
    prevs, items, nexts = tee(some_iterable, 3)
    prevs = chain([None], prevs)
    nexts = chain(islice(nexts, 1, None), [None])
  7. lihuanshuai revised this gist Sep 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    from itertools import tee, islice, chain, izip
    from itertools import tee, islice as , chain, izip

    def previous_and_next(some_iterable):
    prevs, items, nexts = tee(some_iterable, 3)
  8. lihuanshuai created this gist Sep 28, 2017.
    7 changes: 7 additions & 0 deletions previous_and_next.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    from itertools import tee, islice, chain, izip

    def previous_and_next(some_iterable):
    prevs, items, nexts = tee(some_iterable, 3)
    prevs = chain([None], prevs)
    nexts = chain(islice(nexts, 1, None), [None])
    return izip(prevs, items, nexts)