Apr-15-2020, 03:33 PM
You should never remove items from the thing you are iterating. Instead build a new list that has the desired characteristics.
string ='red,red,white,white,pink,blue,white,white,blue,blue,white' wordlist = string.split(',') print(wordlist) # Make a list only containing unique words uniquewords = [word for word in wordlist if wordlist.count(word) == 1] print('Unique colors', uniquewords) # Make a list where each word only occurs once colors = set(wordlist) print('Colors', colors)