Like itertools.pairwise, but for triplets instead of pairs.
(iterable)
| 30 | |
| 31 | |
| 32 | def tripletwise(iterable): # no relation to Jeff |
| 33 | """ |
| 34 | Like itertools.pairwise, but for triplets instead of pairs. |
| 35 | """ |
| 36 | i = iter(iterable) |
| 37 | try: |
| 38 | x, y, z = next(i), next(i), next(i) |
| 39 | except StopIteration: |
| 40 | return |
| 41 | |
| 42 | yield x, y, z |
| 43 | for el in i: |
| 44 | x, y, z = y, z, el |
| 45 | yield x, y, z |
| 46 | |
| 47 | |
| 48 | def skip_whitespace(nodes): |
no outgoing calls