0 votes
1 view
in Python by (41.3k points)

This is the dictionary

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

'color':2}, 

'B':{'speed':60, 

'color':3}}

Using this for loop

for keys,values in cars.items(): 

print(keys) 

print(values)

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 (94.3k 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
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...