Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s = [12, 45, 87,
- [65, 34, 76],
- [34, 76, 43,
- [8, 446, 23, 48,
- [23,56,43,787],
- {"key1": 543, "key2": 65, "key3": [54,2,335,76]}
- ],
- 54, 23, 76, 32
- ],
- 23, 65,
- {"key1": 54, "key2": 234, "key3": {"key1": 234, "key2": [1,245, 56, 45, (45,3,34,56)]}}
- ,23, 765, 22,
- ]
- cem=0
- def calc(s):
- global cem
- if type(s) is list:
- for i in s:
- if type(i) is int:
- cem+=i
- elif type(i) is list:
- calc(i)
- elif type(i) is dict:
- calc(i)
- elif type(i) is tuple:
- calc(i)
- elif type(s) is dict:
- for val in s.values():
- if type(val) is int:
- cem+=val
- elif type(i) is list:
- calc(i)
- elif type(i) is dict:
- calc(i)
- elif type(s) is tuple:
- for i in s:
- if type(i) is int:
- cem+=i
- elif type(i) is list:
- calc(i)
- elif type(i) is dict:
- calc(i)
- return cem
- print(calc(s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement