16 Nested comprehension exercises
(1)
Given this sort of dict (country:city-list):
{'Israel': ['Jerusalem', 'Tel Aviv'],
'USA': ['Boston', 'New York', 'Chicago'],
'China': ['Beijing', 'Shanghai']}
Use a nested list comprehension to produce a list of
tuples that look like (city, country).
(2) Write a function sums_to_n that takes an argument n,
and returns all two-element tuples that sum to n.
sums_to_n(5)
[(0,5), (1,4), (2,3), (4,1), (5,0)]
(3) Produce a list of the unique octets (from
the IP addresses) in mini-access-log.
Given this sort of dict (country:city-list):
{'Israel': ['Jerusalem', 'Tel Aviv'],
'USA': ['Boston', 'New York', 'Chicago'],
'China': ['Beijing', 'Shanghai']}
Use a nested list comprehension to produce a list of
tuples that look like (city, country).
(2) Write a function sums_to_n that takes an argument n,
and returns all two-element tuples that sum to n.
sums_to_n(5)
[(0,5), (1,4), (2,3), (4,1), (5,0)]
(3) Produce a list of the unique octets (from
the IP addresses) in mini-access-log.