I have a list with cities and coordinates.
City = [
('Boston', 42.21, 71.03), ('Los Angeles', 34.03, 118.15) ...
I would also like to learn what i need to do to get the name of the city after i'm asked for coordinate1 and coordinate2.
I would be really grateful if anyone decided to help.
Lists - tuple unpacking
Post a Reply
|Oldest Newest Rating|
· October 26, 2015
To unpack the city list, you would do:
Here, coord1 would be equal to ('Boston', 42.21, 71.03) and coord2, ('Los Angeles', 34.03, 118.15).
Now, if you have coord1, to access it you would do:
because it is the first element in the tuple.
If you want to access it without unpacking, you can do:
This section is all about snakes! Just kidding.
|Bucky Roberts Administrator|