Skip to content

Instantly share code, notes, and snippets.

@eriktaubeneck
Last active December 30, 2015 09:19
Show Gist options
  • Select an option

  • Save eriktaubeneck/7808280 to your computer and use it in GitHub Desktop.

Select an option

Save eriktaubeneck/7808280 to your computer and use it in GitHub Desktop.

Revisions

  1. eriktaubeneck revised this gist Dec 5, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions all_but_last_n.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    from itertools import tee, imap, izip, islice
    from operator import itemgetter

    def all_but_last_n(it,n):
    it1, it2 = tee(it,2)
  2. eriktaubeneck revised this gist Dec 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion all_but_last_n.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@

    def all_but_last_n(it,n):
    it1, it2 = tee(it,2)
    return imap(lambda x:x[0],izip(it1,islice(it2,n,None)))
    return imap(itemgetter(0),izip(it1,islice(it2,n,None)))

    assert [0,1,2] == list(all_but_last_n(xrange(5),2))
  3. eriktaubeneck created this gist Dec 5, 2013.
    7 changes: 7 additions & 0 deletions all_but_last_n.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    from itertools import tee, imap, izip, islice

    def all_but_last_n(it,n):
    it1, it2 = tee(it,2)
    return imap(lambda x:x[0],izip(it1,islice(it2,n,None)))

    assert [0,1,2] == list(all_but_last_n(xrange(5),2))