Python list comprehension: list sub-items without duplicates -


i trying print letters in words in list, without duplicates.

wordlist = ['cat','dog','rabbit'] letterlist = [] [[letterlist.append(x) x in y] y in wordlist] 

the code above generates ['c', 'a', 't', 'd', 'o', 'g', 'r', 'a', 'b', 'b', 'i', 't'], while looking ['c', 'a', 't', 'd', 'o', 'g', 'r', 'b', 'i'].

how modify list comprehension remove duplicates?

if want edit own code:

[[letterlist.append(x) x in y if x not in letterlist] y in wordlist] 

or

list(set([[letterlist.append(x) x in y if x not in letterlist] y in wordlist])) 

else:

list(set(''.join(wordlist))) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -