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

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

Please see the below image for reference:

4条回答
  •  逝去的感伤
    2021-01-29 14:59

    use key and value of your dictionary

    d={1:[2,3],2:[4,5]}
    for k, v in d.items():
        for item in v:
            print(k,' : ',item)
    

提交回复
热议问题