Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

This is the dictionary

cars = {'A':{'speed':70, 




Using this for loop

for keys,values in cars.items(): 



It prints the following:

{'color': 3, 'speed': 60} 

{'color': 2, 'speed': 70}

But I want the program to print it like this:

color : 3 

speed : 60 

color : 2 

speed : 70

I just started learning dictionaries so I'm not sure how to do this.

1 Answer

0 votes
by (106k points)
edited by

To get the desired output that you want for yourself you can use the following code:-

for x in cars:

    print (x) 

   for y in cars[x]: 

        print (y,':',cars[x][y])

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
asked Aug 23, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 2, 2019 in Python by Sammy (47.6k points)

Browse Categories