8000 json.loads withou dupes · ihackit/python-scripts@68d9c41 · GitHub
[go: up one dir, main page]

Skip to content

Commit 68d9c41

Browse files
committed
json.loads withou dupes
1 parent 486b1c3 commit 68d9c41

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

05_load_json_without_dupes.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import json
2+
3+
def dict_raise_on_duplicates(ordered_pairs):
4+
"""reject duplicate keys"""
5+
my_dict = dict()
6+
for key, values in ordered_pairs:
7+
if key in my_dict:
8+
raise ValueError("Duplicate key: {}".format(key,))
9+
else:
10+
my_dict[key] = values
11+
return my_dict

readme.md

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

0 commit comments

Comments
 (0)
0