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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy