How to print a dictionary line by line in Python?

后端 未结 13 1548
情话喂你
情话喂你 2020-11-28 02:02

This is the dictionary

cars = {\'A\':{\'speed\':70,
        \'color\':2},
        \'B\':{\'speed\':60,
        \'color\':3}}

Using this

13条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 02:24

    for car,info in cars.items():
        print(car)
        for key,value in info.items():
            print(key, ":", value)
    

提交回复
热议问题