You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
705 B
Python
32 lines
705 B
Python
import json
|
|
|
|
with open("input") as f:
|
|
document = f.readline().strip()
|
|
|
|
document = json.loads(document)
|
|
|
|
|
|
def iterate_object(json_object):
|
|
object_sum = 0
|
|
object_type = type(json_object)
|
|
|
|
if object_type == list:
|
|
for item in json_object:
|
|
object_sum += iterate_object(item)
|
|
elif object_type == int:
|
|
return json_object
|
|
elif object_type == str:
|
|
pass
|
|
elif object_type == dict:
|
|
for item in json_object.values():
|
|
if item == "red":
|
|
return 0
|
|
object_sum += iterate_object(item)
|
|
else:
|
|
raise TypeError(f"No case for type {object_type}!")
|
|
|
|
return object_sum
|
|
|
|
|
|
print(iterate_object(document))
|