Python, how to print dictionary key and its values in each line?

前端 未结 4 1530
逝去的感伤
逝去的感伤 2021-01-29 14:23

Please see the below image for reference:

4条回答
  •  失恋的感觉
    2021-01-29 14:57

    Probably something like this:

    d = {1:[2,3], 2:[4,5]}
    
    for key in d:
        for i in d[key]:
            print("{0}:{1}".format(key, i))
    
    
    1:2
    1:3
    2:4
    2:5
    

提交回复
热议问题