0

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']

2 Answers2

0

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

list(dt.values())
damaredayo
  • 1,048
  • 6
  • 19
0

The following works:

val = list(dt.values())

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

damaredayo
  • 1,048
  • 6
  • 19