palindrome function

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Jul 12 01:10:09 CEST 2008


Denis Kasak:
> spam = ['a', 'n', 'n', 'a']
> eggs = spam[:]
> if spam.reverse() == eggs:
>     print "Palindrome"

An alternative version:

>>> txt = "anna"
>>> txt == txt[::-1]
True
>>> txt = "annabella"
>>> txt == txt[::-1]
False

Bye,
bearophile



More information about the Python-list mailing list