json.loads withou dupes

This commit is contained in:
Michael Herman 2014-05-03 19:10:43 -05:00
parent 486b1c3bf7
commit 68d9c41cc8
2 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import json
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,))
else:
my_dict[key] = values
return my_dict

View File

@ -4,3 +4,4 @@
1. **02_find_all_links.py**: get all links from a webpage
1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions
3. **04_rename_with_slice.py**: rename group of files, within a single directory, using slice
4. **05_load_json_without_dupes.py: load json, convert to dict, raise error if there is a duplicate key