Python Forum
Finding value in nested dictionaries with lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding value in nested dictionaries with lists
#3
(Mar-07-2020, 09:18 PM)Larz60+ Wrote: At least post the dictionary (or sample of if large) showing the nesting.
access should be quite simple
>>> outerdict = {
...     'value1': 45,
...     'innerdict': {
...         'value2': 75,
...         'value3': 'Peter'
...     }
... }
>>> print(outerdict['innerdict']['value3'])
Peter
>>>

I understand, but I do not know the key of the value, so I can't reference to it directly. I only know the value, and need to return the key to know if the value is found at the correct entry. This due to possible duplicates in the dictionary.

dict = {'nestedA': OrderedDict([('Name', 'TestCase'), ('VarA', 'Local'), ('VarB', None), ('VarC', None), ('VarD', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ('VarE', 'ABCD'), ('VarF', 10.0), ('VarG', False)]), 'nestedB': OrderedDict([('LocA', {'v1': 'ABCD', 'v2': None, 'v3': None, 'v4': [[[0, 1], [1, 1], [2, 2], [0, 4]], [[0, 2], [1, 2], [2, 3], [4, 4]], ['name', 'ABCD']]}), ('LocB', None), ('LocC', None), ('LocD', True), ('LocE', True), ('LocF', False), ('LocG', False)])}
The above is an example. I am looking for the value 'ABCD' and need to return 'nestedA'+'VarE', 'nestedB'+'LocA'+'v1' and 'nestedB'+'LocA'+'v4'+'name'. This because it is presented three times.
Reply


Messages In This Thread
RE: Finding value in nested dictionaries with lists - by mart79 - Mar-08-2020, 07:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List all possibilities of a nested-list by flattened lists sparkt 1 942 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,408 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Comparing items from 2 lists of dictionaries illwill 7 2,824 Sep-14-2020, 10:46 PM
Last Post: bowlofred
  Searching through Nested Dictionaries and Lists Dave_London 1 8,080 Jul-09-2020, 03:36 PM
Last Post: mrdominikku
  Creating Nested Dictionaries Confusion gw1500se 2 2,165 May-18-2020, 11:16 PM
Last Post: gw1500se
  Unpacking nested lists yonatan776 1 2,225 Apr-14-2020, 08:50 PM
Last Post: buran
  Help: for loop with dictionary and nested lists mart79 1 1,885 Apr-12-2020, 02:52 PM
Last Post: TomToad
  nested dictionaries to CSV mart79 9 12,536 Jul-29-2019, 04:59 AM
Last Post: mart79
  Transform simplified dictionary to nested dictionaries bhojendra 1 2,390 Jul-02-2019, 02:05 PM
Last Post: ichabod801
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,311 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020