tails([1,2,3,4,5]) --> [[1,2,3,4,5], [2,3,4,5], [3,4,5], [4,5], [5], []]
(it)
| 27 | # use memory only propertional to the offset difference between the generated |
| 28 | # iterators. |
| 29 | def tails(it): |
| 30 | """ tails([1,2,3,4,5]) --> [[1,2,3,4,5], [2,3,4,5], [3,4,5], [4,5], [5], []] """ |
| 31 | while True: |
| 32 | tail, it = tee(it) |
| 33 | yield tail |
| 34 | next(it) |
| 35 | |
| 36 | # We can now define two new rotations functions. |
| 37 | # The first one is very similar to the above, but since we never keep all list |