0
How to get 2 and 5 in this dictionary?
{"animals": {"dog":{"kind":{"husky":2, "others":5}}}}
3 Answers
+ 2
Assuming the dictionary is named animald, i.e.
animald = {...}
animald["animals"]["dog"]["kind"]["others"]
+ 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
+ 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?