Suppose I have a large list of words. For an example:
>>> with open(\'/usr/share/dict/words\') as f: ... words=[word for word in f.read().split(\'\\
I'd use filter:
filter
>>> words = ['abcd', 'abdef', 'eft', 'egg', 'uck', 'ice'] >>> index = {k.lower() : list(filter(lambda x:x[0].lower() == k.lower(),words)) for k in 'aeiou'} >>> index {'a': ['abcd', 'abdef'], 'i': ['ice'], 'e': ['eft', 'egg'], 'u': ['uck'], 'o': []}