Advertisement
Guest User

Untitled

a guest
Jul 30th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. dummy = object()
  2. def pair(g):
  3. """
  4. yields successive adjacent pairs of values.
  5. the first and last yielded values will be paired with a dummy value, indicating the boundaries of the iterator.
  6. """
  7. last_value = dummy
  8. for item in g:
  9. yield last_value, item
  10. last_value = item
  11. if last_value is not dummy:
  12. yield (last_value, dummy)
  13.  
  14. print(list(pair("hello")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement