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

How do I combine a list of 1 item dicts into a list

As a result of a pymongo query I have a list of 1 item dicts:

[{'id': 453},
 {'id': 365},
 {'id': 311},
 {'id': 523},
 {'id': 367},
 {'id': 891},
 {'id': 621},
 {'id': 215},
 {'id': 819},
 {'id': 218},
 {'id': 711},
 {'id': 212},
 {'id': 409},
 {'id': 200},
 {'id': 893},
 {'id': 219},
 {'id': 832},
...]

I would like to simply have a list of these values : [453,365,...] is there a function that accomplishes this? Otherwise, I guess I could loop through it:

my_list = []
[my_list.append(i['id']) for i in ids]

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

>Solution :

You can make it a oneliner:

my_list = [i['id'] for i in ids]
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