How to print a dictionary line by line in Python?

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

This is the dictionary

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

Using this

相关标签:
13条回答
  • 2020-11-28 02:42

    I prefer the clean formatting of yaml:

    import yaml
    yaml.dump(cars)
    

    output:

    A:
      color: 2
      speed: 70
    B:
      color: 3
      speed: 60
    
    0 讨论(0)
提交回复
热议问题