|
Revision 1121, 0.5 kB
(checked in by arjanmol, 2 years ago)
|
Merged changed from new-canvas branch to trunk
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
ipair function |
|---|
| 3 |
""" |
|---|
| 4 |
|
|---|
| 5 |
def ipair(l): |
|---|
| 6 |
""" |
|---|
| 7 |
This module contains a small utility function that can be used to iterate |
|---|
| 8 |
over a list of items, each item is returned with it's next item. |
|---|
| 9 |
|
|---|
| 10 |
>>> for a, b in ipair((1,2,3,4,5,6)): |
|---|
| 11 |
... print a, b |
|---|
| 12 |
1 2 |
|---|
| 13 |
2 3 |
|---|
| 14 |
3 4 |
|---|
| 15 |
4 5 |
|---|
| 16 |
5 6 |
|---|
| 17 |
""" |
|---|
| 18 |
i = iter(l) |
|---|
| 19 |
last = i.next() |
|---|
| 20 |
while True: |
|---|
| 21 |
new = i.next() |
|---|
| 22 |
yield last, new |
|---|
| 23 |
last = new |
|---|
| 24 |
|
|---|
| 25 |
if __name__ == '__main__': |
|---|
| 26 |
import doctest |
|---|
| 27 |
doctest.testmod() |
|---|