Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dummy = object()
- def pair(g):
- """
- yields successive adjacent pairs of values.
- the first and last yielded values will be paired with a dummy value, indicating the boundaries of the iterator.
- """
- last_value = dummy
- for item in g:
- yield last_value, item
- last_value = item
- if last_value is not dummy:
- yield (last_value, dummy)
- print(list(pair("hello")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement