I have a list of string and some are fragments of a longer word. I just want to keep the longest version of each word fragment.
In the following list I would like to keep the longest word 'indoor outdoor beanbag lounger' and remove the other word fragments.
Example:
list1 = ["indoor outdoor", "indoor outdoor beanbag", "indoor outdoor beanbag lounger"]
Thoughts and things I've tried so far.
I've tried duplicating the list iterating over it and removing the first exact copy of itself. The next step would be to check if a word is found. e.g. is indoor outdoor found in indoor outdoor beanbag if True, then delete from list.
Something along those lines? I've tried looking at Polyfuzz which works to an extent, but I can't seem to fine tune it and there must be a way to solve it by looping though the list.
My code so far which iterates and removes the first exact match from list 2
list1 = ["indoor outdoor", "indoor outdoor beanbag", "indoor outdoor beanbag lounger"]
list2 = ["indoor outdoor", "indoor outdoor beanbag", "indoor outdoor beanbag lounger"]
for i in list1:
cleaned_list = [x for x in list1 if x != i]
print(cleaned_list)