I need to find if some strings in a set are palindromes, irrespective of their case. I am reversing the words in the set, converting them to lowercase, then saying if they match, add it to the palindrom set. When i do it, this is what i get.
TypeError
Traceback (most recent call last)
<ipython-input-1-621af373c5f5> in <module>()
5 print(word, palindrome)
6 wordLower = word.lower
----> 7 if (wordLower==wordLower[::-1]):
8 palindrome.add(word)
TypeError: 'builtin_function_or_method' object is not subscriptable
My code is below.
`words = {'maDam', 'kIng', 'ANna', 'kayak', 'levels', 'dad', 'morning'}
palindrome = set()
for word in words: print(word, palindrome) wordLower = word.lower if (wordLower==wordLower[::-1]): palindrome.add(word)`
word.lower
is the function itself; word.lower()
is the result of calling that function (which it seems what you actually want).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments