I sometimes need to iterate a list in Python looking at the \"current\" element and the \"next\" element. I have, till now, done so with code like:
for curre
A basic solution:
def neighbors( list ): i = 0 while i + 1 < len( list ): yield ( list[ i ], list[ i + 1 ] ) i += 1 for ( x, y ) in neighbors( list ): print( x, y )