Saturday 5 December 2015

Python looping over dictionary


By using items method, we can retrieve the key and corresponding value.

>>> emps1
{1: {'Hari Krishna', 'Gurram'}, 3: {'Shekkappa', 'Mohan'}, 4: {'Ranganath', 'Thippisetty'}, 5: {'Ganji', 'Sudheer'}}
>>> 
>>> for key, value in emps1.items():
...     print(key, value)
... 
1 {'Hari Krishna', 'Gurram'}
3 {'Shekkappa', 'Mohan'}
4 {'Ranganath', 'Thippisetty'}
5 {'Ganji', 'Sudheer'}



Previous                                                 Next                                                 Home

No comments:

Post a Comment