Can someone explain why Python won't let me use i in this manner?
unit1 = [["cats allowed", True], ["bedrooms", 0], ["Balcony", False]]
userPref = []
for i in unit1:
userPref = userPref.append(unit1[i][1])
print(unit1[i][1])
I get this error message:
TypeError: list indices must be integers or slices, not list
If I want to iterate through the second item in each nested list, how would I go about doing that?
(FYI: the for loop in nested in an if statement. I omitted that for simplicity.)
print(i)in the loop you'll understand, you iterate over values, not indicesappendcorrectly, you can see the correct format in my answer