list keys json python 1

list keys json python

>>> dct = {
...     "1": "a", 
...     "3": "b", 
...     "8": {
...         "12": "c", 
...         "25": "d"
...     }
... }
>>> 
>>> dct.keys()
['1', '8', '3']
>>> for key in dct.keys(): print key
...
1
8
3
>>>

Here is what the above code is Doing:
1. We create a dictionary with three keys: “1”, “3”, and “8”.
2. We call the keys() method on the dictionary, which returns a list of the keys.
3. We iterate over the list of keys, printing each key.

Similar Posts