Python Forum
Dictionaries in Lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionaries in Lists
#4
Maybe you can make use of this:
dictionaries = {
    "name1": {'key1': 'value1', 'key2': 'value2'},
    "name2": {'key3': 'value3', 'key4': 'value4'},
    "name3": {'key5': 'value5', 'key6': 'value6'}
}

for dictionary_name, subdictionaries in dictionaries.items():
    print(dictionary_name)
    for key, value in subdictionaries.items():
        print(f"\t{key}:{value}")
Output:
name1 key1:value1 key2:value2 name2 key3:value3 key4:value4 name3 key5:value5 key6:value6

The assignment specifically does not ask for printing name of dict
If OP wants to do this, it can be done with modified assignment. :-)
Reply


Messages In This Thread
Dictionaries in Lists - by szbeco - Nov-05-2019, 10:23 AM
RE: Dictionaries in Lists - by buran - Nov-05-2019, 11:45 AM
RE: Dictionaries in Lists - by szbeco - Nov-05-2019, 12:04 PM
RE: Dictionaries in Lists - by ThomasL - Nov-05-2019, 12:07 PM
RE: Dictionaries in Lists - by szbeco - Nov-05-2019, 12:21 PM
RE: Dictionaries in Lists - by ehmatthes - Nov-06-2019, 03:36 PM
RE: Dictionaries in Lists - by szbeco - Nov-07-2019, 10:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  QUERY on Looping and creating lists as items within dictionaries ajayachander 3 2,399 Mar-26-2020, 02:03 PM
Last Post: ajayachander
  Help with Dictionaries and Lists of Lists Nate5800 5 87,275 Apr-23-2018, 06:42 PM
Last Post: Nate5800

Forum Jump:

User Panel Messages

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