Harsh69
Harsh69

Reputation: 13

TypeError : 'list' object is not callable; What does it mean and how can I solve it?

I am trying to enter a sentence in English and have all of it returned in pig Latin (following a course).

Getting an error on the line temp = strlist(a). How do I solve it??

I have an individual function which can covert a word to pig Latin and another to convert from a sentence to a list of words.

   def pl(word):
    if word[0] in 'aeiou':
        word = word + "ay"
        return word
    else:
        word = word[1:] + word[0] + "ay"
        return word

def linetopiglatin(string):
    strlist = string.split()
    for a in strlist:
        temp = strlist(a)
        temp = pl(temp)
        strlist[a] = temp
        return strlist

Upvotes: 0

Views: 54

Answers (1)

Hiren30598
Hiren30598

Reputation: 64

Hello here error comming becuase you are calling wrong function. strlist is list which is word of list and you have sent that list into pl() function so remove it.

def pl(word):
    if word[0] in 'aeiou':
        word = word + "ay"
        return word
    else:
        word = word[1:] + word[0] + "ay"
        return word

def linetopiglatin(string):
    strlist = string.split()
    for a in strlist:
        #temp = strlist(a)
        temp = pl(a)
        strlist[0] = temp
        return strlist

Upvotes: -1

Related Questions