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

Creating a list of existing dictionaries in python

I need to get a list of some dictionaries that I defined before.The dictionaries look like these:
dic1={"D":1.4,"SD":1.4} dic2={"D":1.2,"SD":1.2,"L":1.6,"LR":1.6,"LR0.5":1.6,"LP":1.6,"LRF":0.5} dic3={"D":1.2,"SD":1.2,"L":1,"LR":1,"LR0.5":1,"LP":1,"LRF":1.6}
And I expect a list like this:

list=[{"D":1.4,"SD":1.4},{"D":1.2,"SD":1.2,"L":1.6,"LR":1.6,"LR0.5":1.6,"LP":1.6,"LRF":0.5},                                                                               {"D":1.2,"SD":1.2,"L":1,"LR":1,"LR0.5":1,"LP":1,"LRF":1.6}]

How can I create it using a loop in python?

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 :

list(filter(lambda a: type(a) == dict, locals().values()))

Will return all local variables with dict type as a list

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