Reputation: 11
I'm trying to write a code in Python 3.x using list comprehension. My code should print letters out of a list and remove duplication.
print(list(set(([letter_list.append(letter) for word in word_list for letter in word]))))
The code runs with no traceback errors but the output is [None]
Upvotes: 1
Views: 88
Reputation: 867
The append
method modifies an (existing) list in place and returns None. A list comprehension creates a new list by itself, so you don't need appending here. Try this:
print(list(set([letter for word in word_list for letter in word])))
Upvotes: 1