Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit68d9c41

Browse files
committed
json.loads withou dupes
1 parent486b1c3 commit68d9c41

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+
importjson
2+
3+
defdict_raise_on_duplicates(ordered_pairs):
4+
"""reject duplicate keys"""
5+
my_dict=dict()
6+
forkey,valuesinordered_pairs:
7+
ifkeyinmy_dict:
8+
raiseValueError("Duplicate key: {}".format(key,))
9+
else:
10+
my_dict[key]=values
11+
returnmy_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)

[8]ページ先頭

©2009-2025 Movatter.jp