1
votes

Why is my code giving error when I am not iterating over an integer?

info = [['Tina', 'Turner', 1939, 'singer'], ['Matt', 'Damon', 1970, 'actor'], ['Kristen', 'Wiig', 1973, 'comedian'], ['Michael', 'Phelps', 1985, 'swimmer'], ['Barack', 'Obama', 1961, 'president']]

last_names=[]
nm=0
for i in info:
    last_names+=i[nm][1]
    nm+=1
This is the wrong site to ask this question, but the error is clearly occuring when iterating over the integer in every nested list (e.g. 1939). This code is not doing what you think it is BTW, just change i[nm][1] to i[1]. - pigeonburger