-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonmenuids.py
23 lines (22 loc) · 989 Bytes
/
jsonmenuids.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
JSON MENU IDS
CHALLENGE DESCRIPTION: You have JSON string which describes a menu. Calculate the SUM of IDs of all "items" in the case a "label" exists for an item.
INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following
{"menu": {"header": "menu", "items": [{"id": 27}, {"id": 0, "label": "Label 0"}, null, {"id": 93}, {"id": 85}, {"id": 54}, null, {"id": 46, "label": "Label 46"}]}}
{"menu": {"header": "menu", "items": [{"id": 81}]}}
{"menu": {"header": "menu", "items": [{"id": 70, "label": "Label 70"}, {"id": 85, "label": "Label 85"}, {"id": 93, "label": "Label 93"}, {"id": 2}]}}
All IDs are integers between 0 and 100. It can be 10 items maximum for a menu.
OUTPUT SAMPLE: Print results in the following way.
46
0
248
"""
import sys
import json
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
if test == "":
break
store = json.JSONDecoder(test)
print store.decode()
test_cases.close()