How to print all the values of a dictionary in Python?

PythonServer Side ProgrammingProgramming

Dictionary object possesses values() method which does this job for us.

>>> D1 = {1:'a', 2:'b', 3:'c'}
>>> D1.values()
dict_values(['a', 'b', 'c'])
>>> list(D1.values())
['a', 'b', 'c']

You can also get corresponding value by iterating through lidt of keys returned by keys() method of dictionary

>>> L1 = list(D1.keys())
>>> for i in L1:
   print (i)
a
b
c
raja
Published on 28-Dec-2017 05:56:31
Advertisements