Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. s = [12, 45, 87,
  2. [65, 34, 76],
  3. [34, 76, 43,
  4. [8, 446, 23, 48,
  5. [23,56,43,787],
  6. {"key1": 543, "key2": 65, "key3": [54,2,335,76]}
  7. ],
  8. 54, 23, 76, 32
  9. ],
  10. 23, 65,
  11. {"key1": 54, "key2": 234, "key3": {"key1": 234, "key2": [1,245, 56, 45, (45,3,34,56)]}}
  12. ,23, 765, 22,
  13. ]
  14. cem=0
  15. def calc(s):
  16. global cem
  17. if type(s) is list:
  18. for i in s:
  19. if type(i) is int:
  20. cem+=i
  21. elif type(i) is list:
  22. calc(i)
  23. elif type(i) is dict:
  24. calc(i)
  25. elif type(i) is tuple:
  26. calc(i)
  27. elif type(s) is dict:
  28. for val in s.values():
  29. if type(val) is int:
  30. cem+=val
  31. elif type(i) is list:
  32. calc(i)
  33. elif type(i) is dict:
  34. calc(i)
  35. elif type(s) is tuple:
  36. for i in s:
  37. if type(i) is int:
  38. cem+=i
  39. elif type(i) is list:
  40. calc(i)
  41. elif type(i) is dict:
  42. calc(i)
  43.  
  44.  
  45.  
  46. return cem
  47. print(calc(s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement