How can I fix this error when I try to find a palindrome?

Coder_Python_123

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)`

Scott Hunter

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.

edited at
0

Comments

0 comments
Login to comment

Related

how to fix error 403 when I try to edit page in WordPress

How can I fix this error when i try to add a database DataSource to visual studio "Table mysql.proc doesn't exist"

When I try to sign in to Mozilla's Backpack I get "Could not verify with browserID!" How can I fix this?

How can i fix this try catch issue

How can I fix this error?

how to fix the error in Jupyter notebook which which i see when i try to import any thing

Thunar says "not authorized to perform this operation" when I try to mount a partition. How can I fix this?

How can i fix the error when installing arpreq in python?

How can i fix this error when converting csv to json

How can I fix this error when deploying to Heroku?

how can i fix this error when installing numpy through cmd?

Install scrapy ERROR - When I try to install scrapy I get the following error that I do not know how to fix it:

How can I find Palindrome numbers in a range using Powershell on VSCode?

how can I write palindrome

When I try to log into my firebase account, I get an error. The error is here but I can't find it

Why using try/catch if I can simply fix the error?

I am getting this error when i try to find a RecyclerView by id

How to fix "mainflipSelectors[i].find" error in jQuery?

How do I fix the error "type annotations needed" when creating a closure that uses the try operator?

How to properly fix the 'error in locking authority file' when I try to start my VNC session

I have an array in a json and when I try to access it with the following code it has an error for multiple words. Can anybody help fix the code

How do I fix this syntax error on my Try and Except

When I try to use string.insert() it tells me there is a length error at memory location... How do I fix this?

How can I solve this error that occurs when I try to sort a nested list based on another nested?

How can i try to read to topic in kafka when i am getting an error as Missing required argument "[topic]"

ngFor won't render accessible data. When I try it breaks my code. How can I fix this?

I have an error when I run it, how do I fix it?

How can I fix This error and what is the cause of it?

How can I fix MySQL error #1064?