Posts

Showing posts from February 7, 2019

Python adding to dictionary only by key

Image
0 0 Let's say i have a city (value) and people (key). 1 city can have many people. (For example.): Code: cities = {'Berlin':{'Dan', 'john'},'Tokyo':{'John'}} city_dict = {} people = {} for city in cities: ? i want to construct a dictionary in python which insert only if a match between keys occurring. (For example the desired result.): {'dan' : {'dan':'berlin','dan':'colorado'},'john' : {'john':'berlin','john':'Tokyo'}} Thanks. python dictionary share | improve this question edited Dec 31 '18 at 11:32 ...