【发布时间】:2020-12-19 19:37:02
【问题描述】:
我有一个列表
carner_list = ['<a href="/lyric/34808442/Loyle+Carner/Damselfly">Damselfly</a>',
'<a href="/lyric/37311114/Loyle+Carner/Damselfly">Damselfly</a>',
'<a href="/lyric/37360958/Loyle+Carner/Damselfly">Damselfly</a>',
'<a href="/lyric/33661937/Loyle+Carner/The+Isle+of+Arran">The Isle of Arran</a>',
'<a href="/lyric/33661936/Loyle+Carner/Mean+It+in+the+Morning">Mean It in the Morning</a>']
现在我想摆脱重复的项目。问题是,双精度项仅在字符串中的特定点 i[38:] 处彼此不同。
我的想法是创建一个 for 循环:
new_list = []
for i in carner_list:
if i[38:] in new_list:
print("found")
else:
new_list = new_list + [i]
print("not")
但这不起作用。
是语法有问题还是我完全走错了路?
最好的拉塞尔
【问题讨论】:
-
您需要带有独特文字的商品吗?
Damselfly,The Isle of Arran? -
您当前的代码有什么输出错误?
-
当您检查来自
carner_list的项目是否也在new_list中时,这将始终评估为False,因为new_list是空的
标签: python string list for-loop if-statement