-3

I get the "main loop 'builtin_function_or_method' object is not iterable" error when I run the code below. The error occurs in for word_search in search_list:

I can't figure out what the built-in function or method is.

end_search=[]
#Remove punctuation
for word_search in search_list:

    #Find punctuation
    if word_search.find('"')>0:
        word_search=word_search.replace('"','')
    if word_search.find("'")>0:
        word_search=word_search.replace("'",'')

    end_search.append(word_search)

This is part of a program to read a text file and return the occurrences of words given in a different text file

1 Answers1

0

So, I just ran the code you provided as such:

search_list = ["hi ' my ' name ' is ' jeremiah", 'this "is " a " list " of " strings']
end_search=[]
#Remove punctuation
for word_search in search_list:

    #Find punctuation
    if word_search.find('"')>0:
        word_search=word_search.replace('"','')
    if word_search.find("'")>0:
        word_search=word_search.replace("'",'')

    end_search.append(word_search)

print(end_search)

It worked fine.

>>>['hi  my  name  is  jeremiah', 'this is  a  list  of  strings']

This leads me to believe the problem is in search_list. Are you making it an actual list before you try to iterate through it or are you trying to iterate through a function or method called search_list? If the case is the latter, it still might work if you iterate through search_list(), but you are better off explicitely creating a list to iterate through just to make sure you avoid funky glitches.