Home > Software engineering >  how to retrieve values from dictionary as list in python? [duplicate]
how to retrieve values from dictionary as list in python? [duplicate]

Time:09-16

how to retrieve values from dictionary as list in python?

I can retrieve values by traversing dict but want to know if there is any method.

example:


dt = {1:'A', 2:'B'}

result:
['A','B']

CodePudding user response:

Something like this can be very easily achieved in python3 by simply doing:

list(dt.values())

CodePudding user response:

Below code works:

val = list(dt.values())

output is: values in dictionary as list : ['A','B']

  • Related