Python - Remove any element from a list of strings that is a substring of another element

前端 未结 8 2105
清酒与你
清酒与你 2020-12-06 10:09

So starting with a list of strings, as below

string_list = [\'rest\', \'resting\', \'look\', \'looked\', \'it\', \'spit\']

I wan

8条回答
  •  离开以前
    2020-12-06 11:10

    Here's an un-optimal way, only use if the lists are small:

    for str1 in string_list:
        for str2 in string_list:
            if str1 in str2:
                string_list.remove(str1)
    

提交回复
热议问题