我有一个字符串列表,需要删除其他项目中包含的项目,如下所示:
a = ["one", "one single", "one single trick", "trick", "trick must", "trick must get", "one single trick must", "must get", "must get the job done"]
我只需要删除同一列表中另一个字符串中包含的每个字符串,例如:“one”包含在“one single”中,因此必须删除,然后“one single”包含在“one single trick”中,因此还需要被丢弃
我努力了:
b=a
for item in a:
for element in b:
if item in element:
b.remove(element)
预期结果:
a = ["trick must get", "one single trick must", "must get the job done"]
任何帮助将不胜感激!提前致谢!
www说
慕斯王
拉风的咖菲猫
子衿沉夜
随时随地看视频慕课网APP
相关分类