Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # collect_dictionary.py
- from collections import defaultdict
- def collect_dictionary(obj):
- inv_obj = defaultdict(list)
- for key, value in obj.items():
- inv_obj[value].append(key)
- return dict(inv_obj)
- ages = {
- 'Peter': 10,
- 'Isabel': 10,
- 'Anna': 9,
- }
- collect_dictionary(ages) # { 10: ['Peter', 'Isabel'], 9: ['Anna'] }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement