Yield pairs of (current, next) items in `it`. `next` is None if `current` is the last item. Example: >>> list(lookahead(x for x in range(6))) [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, None)]
(it)
| 169 | |
| 170 | |
| 171 | def lookahead(it): |
| 172 | """Yield pairs of (current, next) items in `it`. |
| 173 | |
| 174 | `next` is None if `current` is the last item. |
| 175 | Example: |
| 176 | >>> list(lookahead(x for x in range(6))) |
| 177 | [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, None)] |
| 178 | """ |
| 179 | a, b = tee(it) |
| 180 | next(b, None) |
| 181 | return zip_longest(a, b) |
| 182 | |
| 183 | |
| 184 | def regen(it): |
no outgoing calls