0

How to get 2 and 5 in this dictionary?

{"animals": {"dog":{"kind":{"husky":2, "others":5}}}}

30th Mar 2017, 9:32 PM
hamid
hamid - avatar
3 Answers
+ 2
Assuming the dictionary is named animald, i.e. animald = {...} animald["animals"]["dog"]["kind"]["others"]
30th Mar 2017, 9:38 PM
Jehad Al-Ansari
Jehad Al-Ansari - avatar
+ 2
You are lucky, you can use for to get all keys or key, value pairs. Check out this example code for two different methods: https://code.sololearn.com/ck8ik6lkuKwj/?ref=app This is possible, because dictionaries are iterable, i.e. they have an .iter method. I posted very useful links on there topic here: https://www.sololearn.com/discuss/282825/?ref=app
31st Mar 2017, 1:32 AM
Tob
Tob - avatar
+ 1
think we have planet, house and other keys in dictionary, I want a method like "for", to get all keys and values from dictionary. how to write this?
30th Mar 2017, 10:45 PM
hamid
hamid - avatar