Python - Looping through two Dimensional Lists

preview_player
Показать описание
How to loop through 2d lists in Python.
Рекомендации по теме
Комментарии
Автор

Nice!!! Thought of an intuitive solution, but couldn't get the loop to work. Thanks again!!

mistere
Автор

That was very informative in such a short amount of time. Thank you for the explanation!

Xaminn
Автор

Fantastic just what i was looking for, clearly explained thankyou

jsllsj
Автор

thank's a lot sir you helped me to solve my script problem <3

peterkim
Автор

Thanks for previous reply my second question is if i want to match only 1st column of first list with 2nd list what is method?
like:
first list = [home, 1], [people, 2]
2nd list = [home, 1], [street, 2]

i wanna see if from first list "home" is matching, ,,,it should print home in 3rd column as you mentioned before . but i want to list number of second column as well but don't want to match that... i wanna match 1st column only

haider
Автор

how do you compare hommer to other names in list?

murodalisharipov
Автор

Because they're both huge lists and i don't want to paste them in the code, it will get to clumsy and rough

davidling
Автор

wanna ask if i have (two) 2 dimensional list like this and want to find duplicate in two different list what is function? like
first list = [home, 1], [people, 2]
2nd list = [home, 1], [street, 2]

so i know home is same in both so what is function which i can apply

haider
Автор

Lets say I wanted to loop through a 2d list of a 5x5 grid and want to keep checking each time a user input is inserted to see whether or not the user has created a 2x2 grid of 1's inside the 5x5 grid how would you go about doing this.

BobMarley-gmie
Автор

how come the name, age knows whats in the people in the loop ?

carlknightcoph
Автор

When i create a loop and type print it will display all rows and values i need it to but when i print on new line it will only print out the last row with the values. Is there a way to print in new line or create a variable that will display all rows with all values?

Dopeboyz
Автор

Great Video, But my questions is how do i iterate in two files on the system ? pardon my English

davidling
Автор

Thanks for reply that code is working but not in my current file ... actually i am using python and fetched data from mysql ... now i have two records rows1 and rows 2, , i fetched records and converted into Lists which are rows1 and rows2 ...

but when i run this code then code nothing work and dont show errors too

L3=[]
for item1 in rows1:
for item2 in rows2:
if item1[1]==item2[1]:
L3.append(item1)
print(item1)

but when i run this code in another file just to check then it works

L1= [(1, 'Cat'), (2, 'Dog'), (4, 'Elephant')]
L2 = [(1, 'Dog'), (2, 'Zebra'), (3, 'Elephant')]
L3=[]
for item1 in L1:
for item2 in L2:
if item1[1]==item2[1]:
L3.append(item1)
print(item1)

haider
Автор

Explained nothing - just showed how to write the program.

kurtross