Created
December 19, 2019 05:38
-
-
Save luisenriquecorona/6da3241d9075349a4283e099c4775427 to your computer and use it in GitHub Desktop.
The tuple to receive an expression to unpack can have nested tuples, like (a, b, (c, d)) and Python will do the right thing if the expression matches the nesting structure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
metro_areas = [ | |
('Tokyo', 'JP', 36.933, (35.689722, 139.691667)), | |
('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)), | |
] | |
print('{:15} | {:^9} | {:^9}'.format('', 'lat.', 'long.')) | |
fmt = '{:15} | {:9.4f} | {:9.4f}' | |
for name, cc, pop, (latitude, longitude) in metro_areas: | |
if longitude <= 0: | |
print(fmt.format(name, latitude, longitude)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment