【发布时间】:2017-07-08 21:50:16
【问题描述】:
我对 python (2.7) 有点陌生,我很难做到这一点。
我有以下列表:
animal = ['cat', 'cat', 'dog', 'dog', 'dog', 'horse']
names = ['cat_01', 'cat_02', 'dog_01', 'dog_02', 'dog_03', 'horse_01']
我想要以下内容(可以是元组列表或字典)
new = {"cat":('cat_01','cat_02'), "dog":('dog_01','dog_02', 'dog_03'), "horse":('horse_01')}
如何最好地做到这一点?
【问题讨论】:
标签: python python-2.7 list dictionary duplicates