palindrome function

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Jul 11 19:10:09 EDT 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