Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

getting a list of dictionaries as a list of lists

Ok so I have a list of the same dictionaries and I want to get the values of the dictionaries into a list of lists. For example this is what one dictionary might look like:

mylist = [{'a': 0, 'b': 2},{'a':1, 'b':3}]

I want the lists of lists to look like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[[0,2],[1,3]]

I have tried doing

zip(*[d.values() for d in mylist])

however this results in a list of different keys for example:

[[0,1],[2,3]]

>Solution :

As the comments suggest, I don’t think you need zip() for this to work, instead just try something simpler such as [list(i.values()) for i in mylist]
You convert the values into a list with the list() function, and the values are already obtained with the .values() method

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading