How to access List elements


Question

I have a list

list = [['vegas','London'],['US','UK']]

How to access each element of this list?

1
20
5/16/2012 6:40:53 AM

I'd start by not calling it list, since that's the name of the constructor for Python's built in list type.

But once you've renamed it to cities or something, you'd do:

print(cities[0][0], cities[1][0])
print(cities[0][1], cities[1][1])
25
5/16/2012 6:33:54 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon