Nov-05-2019, 10:23 AM
Hi there!
I started learning Python with the help of "Python Crash Course" by Eric Matthes. The progress is good, but I stuck at one of the exercises and sadly, the book doesn't have solutions given away. I tried checking several tutorials before asking here, but no luck.
Here's the task:
I got this far:
The code prints out the keys and values just fine, but even after trying many alternatives, I can't print out the names of the dictionaries. I only manage to print out the whole dictionary. My goal for the print output is this:
Any help is much appreciated!
I started learning Python with the help of "Python Crash Course" by Eric Matthes. The progress is good, but I stuck at one of the exercises and sadly, the book doesn't have solutions given away. I tried checking several tutorials before asking here, but no luck.

Quote:Make several dictionaries. In each dictionary, include keys and values. Store these dictionaries in a list. Next, loop through your list
and as you do print everything you know about each dictionary.
I got this far:
1 2 3 4 5 6 7 8 9 10 |
name1 = { 'key' : 'value' , 'key2' : 'value2' , } name2 = { 'key3' : 'value3' , 'key4' : 'value4' , } name3 = { 'key5' : 'value5' , 'key6' : 'value6' , } names = [name1, name2, name3] for name in names: #????? for keys, values in name.items(): print ( "\t" + keys + ":" + values) |
1 2 3 4 5 6 7 8 9 |
name1: key:value key2:value2 name2: key3:value3 key4:value4 name3: key5:value5 key6:value6 |