palindrome function
Paul McGuire
ptmcg at austin.rr.com
Fri Jul 11 22:15:39 EDT 2008
On Jul 11, 6:20 pm, Mensanator <mensana... at aol.com> wrote:
> > Try this:
>
> > spam = ['a', 'n', 'n', 'a']
> > eggs = spam[:]
> > if spam.reverse() == eggs:
> > print "Palindrome"
>
> You could also do
>
> >>> spam = ['a','n','n','a']
> >>> if spam == [i for i in reversed(spam)]:
>
> print "Palindrome"
>
Or instead of this:
[ i for i in generator_expression]
just use the list constructor:
list(generator_expression)
-- Paul
More information about the Python-list
mailing list