如何在python中以这种方式打印字典

时间:2015-10-24 05:00:11

标签: python dictionary printing

{1: ['Antil', '(AR,82)', '(BIO2,71)', '(DAPA,64)', '(EXC,43)', '(SLIP,40)'], 2: ['Josh', '(CCN,82)', '(COC,49)', '(IAML,72)'], 3: ['Andry', '(ES,98)', '(TTS,97)']}

嗨,这是字典,如何在python中以下列格式打印出来,非常感谢

Antil-->(AR,82)(BIO2,71)(DAPA,64)(EXC,43)(SLIP,40)
Josh-->(CCN,82)(COC,49)(IAML,72)
Andry-->(ES,98)(TTS,97)

1 个答案:

答案 0 :(得分:4)

d = {1: ['Antil', '(AR,82)', '(BIO2,71)', '(DAPA,64)', '(EXC,43)', '(SLIP,40)'], 2: ['Josh', '(CCN,82)', '(COC,49)', '(IAML,72)'], 3: ['Andry', '(ES,98)', '(TTS,97)']}

for k,v in sorted(d.items()):
    print("{0}-->{1}".format(v[0],''.join(v[1:])))