Re: palindrome function

2008-07-12 Thread Terry Reedy
Mensanator wrote: It hasn't. and here's why: IDLE 2.6b1 seq=['a','n','n','a'] seq.reversed() Traceback (most recent call last): File "", line 1, in seq.reversed() AttributeError: 'list' object has no attribute 'reversed' My apologies. reversed() is a builtin func, not a method, a

Re: palindrome function

2008-07-12 Thread Mensanator
On Jul 12, 2:18�pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Peter Otten wrote: > > Denis Kasak wrote: > > >> Basically, it reverses the list in place, so it modifies the list which > >> called it. It does not return a /new/ list which is a reversed version > >> of the original, as you expected it

Re: palindrome function

2008-07-12 Thread Terry Reedy
Peter Otten wrote: Denis Kasak wrote: Basically, it reverses the list in place, so it modifies the list which called it. It does not return a /new/ list which is a reversed version of the original, as you expected it to. Since it doesn't return anything explicitly, Python makes it return None

Re: palindrome function

2008-07-12 Thread Denis Kasak
Peter Otten wrote: Denis Kasak wrote: Basically, it reverses the list in place, so it modifies the list which called it. It does not return a /new/ list which is a reversed version of the original, as you expected it to. Since it doesn't return anything explicitly, Python makes it return None.

Re: palindrome function

2008-07-11 Thread Peter Otten
Denis Kasak wrote: > Basically, it reverses the list in place, so it modifies the list which > called it. It does not return a /new/ list which is a reversed version > of the original, as you expected it to. Since it doesn't return anything > explicitly, Python makes it return None. Hence, the com

Re: palindrome function

2008-07-11 Thread Paul McGuire
On Jul 11, 6:20 pm, Mensanator <[EMAIL PROTECTED]> 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)]: > >         pri

Re: palindrome function

2008-07-11 Thread Hugh M
> Basically, it reverses the list in place, so it modifies the list which > called it. It does not return a /new/ list which is a reversed version of > the original, as you expected it to. Since it doesn't return anything > explicitly, Python makes it return None. Hence, the comparison you are doin

Re: palindrome function

2008-07-11 Thread Mensanator
On Jul 11, 5:34 pm, Denis Kasak <[EMAIL PROTECTED]> wrote: > On Sat, Jul 12, 2008 at 12:22 AM, kdt <[EMAIL PROTECTED]> wrote: > >  > Hi all, >  > >  > Can someone please explain to me why the following evaluates as false? >  > >  list=['a','n','n','a'] >  list==list.reverse() >  False >

Re: palindrome function

2008-07-11 Thread bearophileHUGS
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 -- http://mail.python.org/mailman/listinfo/python-

Re: palindrome function

2008-07-11 Thread kdt
On Jul 11, 11:34 pm, Denis Kasak <[EMAIL PROTECTED]> wrote: > On Sat, Jul 12, 2008 at 12:22 AM, kdt <[EMAIL PROTECTED]> wrote: > >  > Hi all, >  > >  > Can someone please explain to me why the following evaluates as false? >  > >  list=['a','n','n','a'] >  list==list.reverse() >  False

Re: palindrome function

2008-07-11 Thread Denis Kasak
On Sat, Jul 12, 2008 at 12:22 AM, kdt <[EMAIL PROTECTED]> wrote: > Hi all, > > Can someone please explain to me why the following evaluates as false? > list=['a','n','n','a'] list==list.reverse() False > > I'm stumped :s Read the documentation on list.reverse(). Basically, it reverse

palindrome function

2008-07-11 Thread kdt
Hi all, Can someone please explain to me why the following evaluates as false? >>>list=['a','n','n','a'] >>>list==list.reverse() >>>False I'm stumped :s -- http://mail.python.org/mailman/listinfo/python-list