Re: Strange behavior with sort()

2014-02-26 Thread Larry Hudson
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx sort() sorts the sequence in pla

Re: Strange behavior with sort()

2014-02-26 Thread Gary Herron
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: Most such questions can be answered by printing out the values in question and observi

Re: Strange behavior with sort()

2014-02-26 Thread ast
Thanks for the very clear explanation -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with sort()

2014-02-26 Thread Marko Rauhamaa
"ast" : > if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? The list.sort() method returns None. The builtin sorted() function returns a list: if sorted(box) == [1, 2, 3]: would work. Note that the list.sort() method is often preferred because

Re: Strange behavior with sort()

2014-02-26 Thread Lele Gaifax
"ast" writes: > If I write: > >box.sort() >if box == [1, 2, 3]: > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? Because very often methods **dont't** return the object they are applied (self that is).

Re: Strange behavior with sort()

2014-02-26 Thread Eduardo A . Bustamante López
On Thu, Feb 27, 2014 at 07:24:24AM +0100, ast wrote: > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Wh

Re: Strange behavior with sort()

2014-02-26 Thread Frank Millman
"ast" wrote in message news:530eda1d$0$2061$426a7...@news.free.fr... > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test alwa

Strange behavior with sort()

2014-02-26 Thread ast
Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx -- https://mail.python.org/mailman/listinfo/python-list