City with Highest Population (Problem 39) - InfyTQ Solution in Python

City with Highest Population (Problem 39)

InfyTQ Solution in Python



PROBLEM STATEMENT

Suppose you are given a data structure which is a list of dictionaries as follows:

cities = [
{'Name':'Vancouver','State':'WA','Population':161791},
{'Name':'Salem','State':'OR','Population':154637},
{'Name':'Seattle','State':'WA','Population':608660},
{'Name':'Spokane','State':'WA','Population':208916},
...
]


Complete the function max_in_state to return the city (as a dictionary) with the highest population in a given state. If the population is a tie then return the city that comes first alphabetically.

If cities contained only the dictionaries above, a call to max_in_state(cities, 'WA') would return:
{'Name':'Seattle','State':'WA','Population':608660}






SOLUTION
SHARE If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
Newer Posts Newer Posts Older Posts Older Posts

More posts

Comments

Post a Comment

Sponsored Content