Clinton Vlasak Clinton Vlasak - 6 months ago 24
Python Question

Find index of all words with letter 'x' from separate text file

how would I sparse through every index of a list and find every word containing an 'x'? I'm trying to use use enumerate and print the results within brackets, but i'm not sure how to do it.

Thank you

wordsFile = open("words.txt", 'r')
words =
wordList = words.split()


for (index, value) in enumerate(wordList):
if value == 'x':

print("These locations contain words containing the letter 'x':\n",indices)


Your code is almost complete:

for (index, value) in enumerate(wordList):
    if 'x' in value:

This checks, for every single word, if there is an x in it. If so, it adds the index to indices.