json.loads withou dupes
This commit is contained in:
parent
486b1c3bf7
commit
68d9c41cc8
11
05_load_json_without_dupes.py
Normal file
11
05_load_json_without_dupes.py
Normal 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
|
@ -4,3 +4,4 @@
|
|||||||
1. **02_find_all_links.py**: get all links from a webpage
|
1. **02_find_all_links.py**: get all links from a webpage
|
||||||
1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions
|
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
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user