example-code-2e/02-array-seq/metro_lat_lon.py

30 lines
833 B
Python
Raw Normal View History

2019-11-21 00:19:50 +01:00
"""
metro_lat_long.py
Demonstration of nested tuple unpacking::
>>> main()
2021-06-26 18:42:28 +02:00
| latitude | longitude
2019-11-21 00:19:50 +01:00
Mexico City | 19.4333 | -99.1333
New York-Newark | 40.8086 | -74.0204
Sao Paulo | -23.5478 | -46.6358
"""
2014-10-14 19:26:55 +02:00
metro_areas = [
2021-06-26 18:42:28 +02:00
('Tokyo', 'JP', 36.933, (35.689722, 139.691667)), # <1>
2014-10-14 19:26:55 +02:00
('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)),
('Mexico City', 'MX', 20.142, (19.433333, -99.133333)),
('New York-Newark', 'US', 20.104, (40.808611, -74.020386)),
('Sao Paulo', 'BR', 19.649, (-23.547778, -46.635833)),
]
2019-11-21 00:19:50 +01:00
def main():
2021-06-26 18:42:28 +02:00
print(f'{"":15} | {"latitude":>9} | {"longitude":>9}')
for name, _, _, (lat, lon) in metro_areas: # <2>
if lon <= 0: # <3>
print(f'{name:15} | {lat:9.4f} | {lon:9.4f}')
2019-11-21 00:19:50 +01:00
if __name__ == '__main__':
main()