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]]

1st May 2020, 12:59 AM
Casc
Casc - avatar
3 Antworten
+ 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...
1st May 2020, 1:23 AM
Peter Parker
Peter Parker - avatar
0
# with list comprehension: res = [lst[3] for lst in Phones]
1st May 2020, 2:40 PM
visph
visph - avatar