Monday, February 19, 2018

python - Finding first occurrence of a character in a word



what I am trying to do:

By filtering the lowers list, create and print a list of the words which satisfy all of the following criteria:



the word is at least 6 characters long;
the word contains the letter 'e' at least 3 times;
the first occurrence of the letter 'e' is in the second half of the word.



I have this so far:
was used earlier:



words = [ line.strip() for line in file(DATA+'english_wordlist.txt') ]



(lowers was defined earlier in my work as a partial set of words)



[word for word in lowers if len(word)>=6 and word.count('e')>=3 and 'e' is after word(len(word)/2::)]


I know that 'e' is after word(len(word)/2::) is wrong but this just my rough logic. How exactly would i accomplish this?


Answer



and word.index('e') >= len(word)/2


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...