Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.22 KB | None | 0 0
  1. import itertools
  2.  
  3. def strip_last(it, n=1):
  4. it1, it2 = itertools.tee(it)
  5. try:
  6. for i in range(n):
  7. next(it2)
  8. except StopIteration:
  9. return
  10. for (x, _) in zip(it1, it2):
  11. yield x
Add Comment
Please, Sign In to add comment