Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Helpers with iterator
4"""
7def iterator_prev_next(iter):
8 """
9 iterator on a sequence and returns another iterator with
10 ``previous item, current item, next item``,
12 @param iter iterator
13 @return iterator
15 the previous item is ``None`` at the beginning of the sequence,
16 the next item is the same at the end of the sequence
17 """
18 prev, item, next = None, None, None
19 notempty = False
20 for current in iter:
21 notempty = True
22 prev = item
23 item = next
24 next = current
25 if item is not None:
26 yield prev, item, next
27 if notempty:
28 prev = item
29 item = next
30 next = None
31 yield prev, item, next