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
Post a Comment