python assignment of complex objects
Question: I have following code which works fine. but the minute I remove comment across
statement print `list(B)` it fails and returns as an empty list. I'm thinking
perhaps X is getting address location of `list(B)` executed as part of print
statement.

    
    
    import itertools
    A = [1,2,3]
    B = itertools.product(A,repeat=2)
    print str(B)
    #print list(B)
    X = list(B)
    print X
    <itertools.product object at 0x7f5ac40a9a50>
    [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)]
    Command took 0.03s 
    


Answer: `B` is an _iterator_. If you ask for `list(B)` then you will _exhaust the
iterator_ , causing it to be empty the next time you do `list(B)`.

As a rule-of-thumb: when dealing with iterators, you rarely need to assign
them to names. Usually, you either just iterate over the iterator with `for-
in`, or you use `list` to convert the iterator into a list.

