Python Dict to List

June 28, 2019
d = {1: 'Apple', 2: 'Orange', 3: 'Pear'}

Get Keys

data = d.keys()
[1, 2, 3]

Get Values

data = d.values()
['Apple', 'Orange', 'Pear']

Get Key and Value as Tuble

data = d.items()
[(1, 'Apple'), (2, 'Orange'), (3, 'Pear')]
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.