So the question was to create a function which takes a list of documents (each document is a string) and a keyword. It should return a list of the index values into the original list for all documents containing the keyword.
Example (the result should be [0]):
doc_list = ["The Learn Python Challenge Casino.", "They bought a car", "Casinoville"]
word_search(doc_list, 'casino')
I tried list comprehensions and I don't know where it went wrong. Here's my code:
def word_search(doc_list, keyword):
indices=[]
for i, doc in enumerate(doc_list):
indices =[i for word in doc.split(" ") if word.lower().strip(".,")== keyword.lower()]
return indices