Python - step through list -TypeError: 'int' object is not iterable
Question: Trying to learn python, I am trying to do:

    
    
    list0=['A','B'];
    list1=['C','D'];
    z=0
    while z < 2:
        for q in list(z):
            print q
        z += 1
    

I would like it to print

    
    
    A
    B
    C
    D
    

but i get the following error:

    
    
    Traceback (most recent call last):
      File "main.py", line 6, in 
        for q in list(z):
    TypeError: 'int' object is not iterable
    

Is this possible in python? I know I have done this or something similar in
other languages.


Answer:   1. You can gather both the lists as another list and then you can index it like this
    
        list0=['A','B']           # We don't need semicolons
    list1=['C','D']
    lists=[list0, list1]      # Create a list of lists
    z=0
    while z < 2:
        for q in lists[z]:    # We access list's index with [], not with ()
            print q
        z += 1
    

**Output**

    
        A
    B
    C
    D
    

  2. The same effect can be achieved like this
    
        for current_list in [list0, list1]:
        for current_item in current_list:
            print current_item
    

  3. There is a builtin python module, which comes with a [`itertools.chain`](http://docs.python.org/2/library/itertools.html#itertools.chain) method, which can be used like this
    
        import itertools
    for current_item in itertools.chain(list0, list1):
        print current_item
    

