Monday, 19 February 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...