-1

How to convert my dict value in a list?

Input

My_dict={{'x':112,'y':987,'z':56},{'x':12,'y':97,'z':516},{'x':1912,'y':7,'z':26},...}

Output

My_list=[[112,987,56],[12,97,516],[1912,7,26],...]
Beyond
  • 21
  • 3
  • 1
    Does this answer your question? [How can I get list of values from dict?](https://stackoverflow.com/questions/16228248/how-can-i-get-list-of-values-from-dict) ... do this in a loop or list comprehension. – mkrieger1 Dec 20 '22 at 10:18
  • 2
    `My_dict` is not a valid data structure. It seems that it is a dict of dict, but the first layer has no key, only values. Did you mean `My_dict=[{'x':112,'y':987,'z':56},{'x':12,'y':97,'z':516},{'x':1912,'y':7,'z':26}]` ? – Itération 122442 Dec 20 '22 at 10:19
  • Please show us what you've tried. – U13-Forward Dec 20 '22 at 10:19
  • It's working using that link 'How can I get lost of values from dict?' – Beyond Dec 20 '22 at 10:30
  • My_dict={'1': {'x':112,'y':987,'z':56}, '2': {'x':12,'y':97,'z':516}, '3': {'x':1912,'y':7,'z':26}} print(My_dict) My_list = [] for key, value in My_dict.items(): tmpList = [] for key2, value2 in value.items(): tmpList.append(value2) My_list.append(tmpList) print(My_list) – Vanfen Dec 20 '22 at 10:30

1 Answers1

0

Most likely you meant

my_list_of_dicts =[{'x':112,'y':987,'z':56},
         {'x':12,'y':97,'z':516},
         {'x':1912,'y':7,'z':26}]

Because the data structure is not correct for your My_dict.

If so, you can use list comprehension as below

[list(inner_dict.values()) for inner_dict in my_list_of_dicts]
aykcandem
  • 806
  • 1
  • 6
  • 18