Go through 2D list in Python

1

I have the code below and I want to go through and display item by item from this list. However, I can not do this because the entire list is displayed. I ask for your help.

lista = [[10,20,30,40],[50,60,70,80]]
i = 0
for i in range(2):
    print (lista[i])
    
asked by anonymous 23.02.2017 / 20:29

1 answer

3

Cycle within the other (nested):

for sublista in lista:
    for item in sublista:
        print item

Or if you do not need to do anything to the sublists you can do the flat list:

 print '\n'.join(str(item) for sub in lista for item in sub) 
    
23.02.2017 / 20:31