Skip to content

Instantly share code, notes, and snippets.

@mayankdawar
Created February 22, 2020 20:50
Show Gist options
  • Save mayankdawar/e53d3b0b2ac830d5be00064de76255a0 to your computer and use it in GitHub Desktop.
Save mayankdawar/e53d3b0b2ac830d5be00064de76255a0 to your computer and use it in GitHub Desktop.
A palindrome is a phrase that, if reversed, would read the exact same. Write code that checks if p_phrase is a palindrome by reversing it and then checking if the reversed version is equal to the original. Assign the reversed version of p_phrase to the variable r_phrase so that we can check your work.
p_phrase = "was it a car or a cat I saw"
r_phrase = p_phrase[::-1]
@SarahAmiraslani
Copy link

Why can't we use the reverse() method?

@mayankdawar
Copy link
Author

Why can't we use the reverse() method?

reverse() function can only be used in case of lists. It will show an error if we use this for string.

@siddharthnagu
Copy link

Thank you

@IldarValishev
Copy link

IldarValishev commented May 30, 2021

p_phrase = "was it a car or a cat I saw"
phrase = []
for letter in p_phrase:
phrase.append(letter)
phrase.reverse()
r_phrase= ''
r_phrase = "".join(phrase)
print(r_phrase)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment