Answer by ZenGyro for How to go from list of words to a list of distinct...
words = 'She sells seashells by the seashore'ltr = list(set(list(words.lower())))ltr.remove('')print ltr
View ArticleAnswer by Mike Graham for How to go from list of words to a list of distinct...
Sets provide a simple, efficient solution.words = 'She sells seashells by the seashore'unique_letters = set(words.lower())unique_letters.discard('') # If there was a space, remove it.
View ArticleAnswer by SilentGhost for How to go from list of words to a list of distinct...
here are some timings made with py3k:>>> import timeit>>> def t(): # mine (see history) a = {i.lower() for i in words} a.discard('') return a>>>...
View ArticleAnswer by ephemient for How to go from list of words to a list of distinct...
>>> set('She sells seashells by the seashore'.replace('', '').lower())set(['a', 'b', 'e', 'h', 'l', 'o', 's', 'r', 't', 'y'])>>> set(c.lower() for c in 'She sells seashells by the...
View ArticleAnswer by Ignacio Vazquez-Abrams for How to go from list of words to a list...
set(l for w in word_list for l in w)
View ArticleAnswer by Eli Bendersky for How to go from list of words to a list of...
Make ltr a set and change your loop body a little:ltr = set()for word in word_list: for c in word: ltr.add(c)Or using a list comprehension:ltr = set([c for word in word_list for c in word])
View ArticleAnswer by danben for How to go from list of words to a list of distinct...
set([letter.lower() for letter in words if letter != ''])Edit: I just tried it and found this will also work (maybe this is what SilentGhost was referring to):set(letter.lower() for letter in words if...
View ArticleHow to go from list of words to a list of distinct letters in Python
Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence.Here's my current code:words = 'She sells seashells by the seashore'ltr = []# Convert...
View Article
More Pages to Explore .....