python-scripts/scripts/05_load_json_without_dupes.py

10 lines
293 B
Python
Raw Normal View History

2014-05-04 02:10:43 +02:00
def dict_raise_on_duplicates(ordered_pairs):
"""reject duplicate keys"""
my_dict = dict()
for key, values in ordered_pairs:
if key in my_dict:
raise ValueError("Duplicate key: {}".format(key,))
2014-05-04 02:10:43 +02:00
else:
my_dict[key] = values
return my_dict