1

Can anybody help me and tells me what is the thing that is missing

class Palindrome:

  @staticmethod
  def is_palindrome(word):
    copy_ = word[-1:]
    if word == copy_:
       return True
     else:
       return False


  print(Palindrome.is_palindrome("deleveled"))
Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128

2 Answers2

5

Change:

copy_ = word[-1:]

To:

copy_ = word[::-1]
WholesomeGhost
  • 1,101
  • 2
  • 17
  • 31
2

word[-1:] just returns the last character of the word.

Replace

copy_ = word[-1:]

with

copy_ = word[::-1]

The [::-1] slice inverting the string

Another method is to use reverse function.

copy_ = ''.join(reversed(word))

Note: word[::-1] is faster.

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128
  • @MihaiAlexandru-Ionut reason for `word[::-1]` being faster? – Jeru Luke May 07 '18 at 10:38
  • 1
    @JeruLuke Timings (and the reasons for them) for various ways to implement reversing a string are given in https://stackoverflow.com/questions/931092/reverse-a-string-in-python. – BoarGules May 07 '18 at 12:06