when I execute the following code I get ['red', 'pink', 'red', 'white', 'blue']. I cannot understand why there are 2 'red' words. Can someone help me with this?
string ='red,red,white,white,pink,blue,red,white,blue'
wordlist = string.split(',')
for word in wordlist:
if wordlist.count(word) > 1:
wordlist.remove(word)
print(wordlist)
thank you
string ='red,red,white,white,pink,blue,red,white,blue'
wordlist = string.split(',')
for word in wordlist:
if wordlist.count(word) > 1:
wordlist.remove(word)
print(wordlist)
thank you
(Apr-15-2020, 02:46 PM)garam0 Wrote: when I execute the following code I get ['red', 'pink', 'red', 'white', 'blue']. I cannot understand why there are 2 'red' words. Can someone help me with this?
string ='red,red,white,white,pink,blue,red,white,blue'
wordlist = string.split(',')
for word in wordlist:
if wordlist.count(word) > 1:
wordlist.remove(word)
print(wordlist)
thank you
[python]string ='red,red,white,white,pink,blue,white,white,blue,blue,white'
wordlist = string.split(',')
print(wordlist)
i = 0
for word in wordlist:
if wordlist.count(word) > 1:
wordlist.remove(word)
print(wordlist)[/python]
