Python Forum

Full Version: Finding value in nested dictionaries with lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Of course it doesn't - your instance checks are for dicts, lists and strings and an object of type Foo for example is not one of those things. Where did this problem come from? Is this really the right kind of structure for the data?
(Mar-08-2020, 04:55 PM)ndc85430 Wrote: [ -> ]Of course it doesn't - your instance checks are for dicts, lists and strings and an object of type Foo for example is not one of those things. Where did this problem come from? Is this really the right kind of structure for the data?

This structure was given to me. Hence, I need to work with what I have and search through this structure as it is. Independent of whether it is good or bad. Is there a possibility of reading this part of the dictionary too without restructuring the data?
Well of course. You can call whatever methods you need on those objects, or check the fields you need when you encounter them and then process the values in the same way you're doing elsewhere.

Who would set up a problem like this though?!
(Mar-08-2020, 06:33 PM)ndc85430 Wrote: [ -> ]Well of course. You can call whatever methods you need on those objects, or check the fields you need when you encounter them and then process the values in the same way you're doing elsewhere.

Who would set up a problem like this though?!

Can you give me some pointers on how to search through these objects to find the variable that contains the string I am looking for?

Who is not important I think, it is more that this is all I have and if there is a solution, I would like to know.
I'm not sure what you mean by search - just call the relevant methods, or check the values of whatever fields.
(Mar-08-2020, 07:15 PM)ndc85430 Wrote: [ -> ]I'm not sure what you mean by search - just call the relevant methods, or check the values of whatever fields.

I ment that I need to look for a certain keyword in a dictionary with one of the dictionary entries being the "checking.check.assessment" object but, how do I get access to it and 'search' through this object for the keyword while going through the recursive loop. Or am I missing something...
The same way you're doing with anything else - you can check whether the value is of that type and if so, do what you need with it.
Pages: 1 2