0
Python accessing nested lists
How do I access the every elements in index(3) in the nested list ? Phones = [[âIphone11â, âAppleâ, 6.1, 3110, 1280], [âGalaxyS20â, âSamsungâ, 6.2, 4000, 1348], [âNova 5Tâ, âHuaweiâ, 6.26, 3750, 497], [âReno Zâ, âOppoâ, 6.4, 4035, 397]] For example: I want to access index(3) in the list of phones Which return would [[3110,4000,3750,4035]]
3 Answers
+ 1
Try this
L= []
For item in Phones:
L.append(int(item[3]))
print(L)
In first iteration item will represent 1st list, in second iteration the second list & so on...
0
# with list comprehension:
res = [lst[3] for lst in Phones]