我对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')}
如何最好地做到这一点?
这会改变'in'运算符的'str.startwith'。因为我正在处理不以我需要的字符串开头的文件路径。不管怎样,谢谢你! –
如果是这样,我已经改变了这个片段。它会工作 – RomanPerekhrest