TypeError: 'str' object is not callable (python 2) -



TypeError: 'str' object is not callable (python 2) -

program check if word starts & ends same letter

def match_letter(): count = 0 word in words: if len(word) >=2 , word[0] == word[-1]: count = count + 1 homecoming count def main(): words = [] words_list = raw_input('enter words: ') words_list = words_list().split() word in words_list: words.append(word) count = match_letter() print 'letter matched %d ' %count if __name__ == '__main__': main()

this python code, giving error

traceback (most recent phone call last): file "d:\programming\python\python 2.7\same_letter.py", line 21, in <module> main() file "d:\programming\python\python 2.7\same_letter.py", line 13, in main words_list = words_list().split() typeerror: 'str' object not callable

i thankful if can help me..

this line has parentheses

words_list = words_list().split()

it

words_list = words_list.split()

in fact, have number of extraneous steps, code block

words = [] words_list = raw_input('enter words: ') words_list = words_list().split() word in words_list: words.append(word)

could reduced to:

words = raw_input('enter words: ').split()

and if understand question, solve using slicing

def same_back_and_front(s): homecoming s[0] == s[-1] # first letter equals lastly letter >>> words = ['hello', 'test', 'yay', 'nope'] >>> [word word in words if same_back_and_front(word)] ['test', 'yay']

python

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -