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 to check if a dictionary contains a list with a dictionary inside?

I am wondering how I would go about doing a validation check to see if a dictionary contains a list with another dictionary inside the list? Here is my dictionary that I need to validate: {‘custom_orders’: [{‘190’: 3}, {‘191’: 2}]}

>Solution :

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

If you just need to check if a list contains dictionaries and nothing else you can try this:

list_to_test = [{'190': 3}, {'191': 2}]
all((map(lambda e: isinstance(e, dict), list_to_test)))
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