Walk two lists (no zip)
Question: This is my implementation:

    
    
    def walk_two(a, b):
        for x in a:
            for y in b:
                yield x, y
    
    a = xrange(2)
    b = xrange(3)
    
    for x, y in walk_two(a, b):
        print x, y
    

With this output:

    
    
    0 0
    0 1
    0 2
    1 0
    1 1
    1 2
    

Is there a better (more pythonic) way of doing that? A built-in? A more
generic walkN?


Answer: You are looking for `itertools.product`:

    
    
    from itertools import product
    a = xrange(2)
    b = xrange(3)
    
    for x, y in product(a, b):
        print x, y
    

