Re: Python 3 sort() problem

2015-08-17 Thread Rustom Mody
On Monday, August 17, 2015 at 7:32:08 PM UTC+5:30, Владислав wrote: > # first: works fine > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)) > x.sort() > print(x)  # output: 1, 2, 3, 4 > > # second: why x became None ?? > x = [1, 2, 4, 2, 1, 3] > x = list(set(x)).sort() > print(x)  # output: None > I kno

Re: Python 3 sort() problem

2015-08-17 Thread Mark Lawrence
On 17/08/2015 12:42, Владислав wrote: # first: works fine x = [1, 2, 4, 2, 1, 3] x = list(set(x)) x.sort() print(x) /# output: 1, 2, 3, 4 /# second: why x became None ?? x = [1, 2, 4, 2, 1, 3] x = list(set(x)).sort() print(x) /# output: None/ I know that sort() returns None, but I guess that

Re: Python 3 sort() problem

2015-08-17 Thread Fabien
On 08/17/2015 01:42 PM, Владислав wrote: x = [1, 2, 4, 2, 1, 3] x = list(set(x)).sort() print(x) /# output: None/ I know that sort() returns None, but I guess that it would be returned x that was sorted. Why so? If sort() returns None, than the following: x = list(set(x)).sort() is equivalen

Re: Python 3 sort() problem

2015-08-17 Thread Joonas Liik
> > I know that sort() returns None, but I guess that it would be returned x > that was sorted. Why so? if it returned a sorted list it might lead some people to believe it did not modify the oridinal list which would lead to a ton of confusion for new users. -- https://mail.python.org/mailman/li

Python 3 sort() problem

2015-08-17 Thread Владислав
# first: works fine x = [1, 2, 4, 2, 1, 3] x = list(set(x)) x.sort() print(x) # output: 1, 2, 3, 4 # second: why x became None ?? x = [1, 2, 4, 2, 1, 3] x = list(set(x)).sort() print(x) # output: None I know that sort() returns None, but I guess that it would be returned x that was sorted. Wh

Re: sort problem

2005-10-21 Thread Alex Martelli
Michele Petrazzo <[EMAIL PROTECTED]> wrote: > Lasse Vågsæther Karlsen wrote: > > How about: > > > > list.sort(key=lambda x: x[3]) > > > > Does that work? > > Yes, on my linux-test-box it work, but I my developer pc I don't have > the 2.4 yet. I think that this is a good reason for update :) Up

Re: sort problem

2005-10-21 Thread Michele Petrazzo
Kent Johnson wrote: > or learn about decorate-sort-undecorate: > > lst = [ ...whatever ] lst = [ x[3], i, x for i, x in enumerate(lst) ] > I think that here the code must be changed (for the future): lst = [ (x[3], i, x) for i, x in enumerate(lst) ] > lst.sort() lst = [ x for _, _, x in lst ]

Re: sort problem

2005-10-20 Thread Kent Johnson
Michele Petrazzo wrote: > Lasse Vågsæther Karlsen wrote: > >> How about: >> >> list.sort(key=lambda x: x[3]) Better to use key=operator.itemgetter(3) > Yes, on my linux-test-box it work, but I my developer pc I don't have > the 2.4 yet. I think that this is a good reason for update :) or learn

Re: sort problem

2005-10-20 Thread Michele Petrazzo
Lasse Vågsæther Karlsen wrote: > How about: > > list.sort(key=lambda x: x[3]) > > Does that work? > Yes, on my linux-test-box it work, but I my developer pc I don't have the 2.4 yet. I think that this is a good reason for update :) Thanks, Michele -- http://mail.python.org/mailman/listinfo/py

Re: sort problem

2005-10-20 Thread Lasse Vågsæther Karlsen
How about: list.sort(key=lambda x: x[3]) Does that work? -- http://mail.python.org/mailman/listinfo/python-list

sort problem

2005-10-20 Thread Michele Petrazzo
I have a list of lists (a grid table) that can have about 15000 - 2 "rows" and 10 "cols", so: 1 [ [ 'aaa', 'vv', 'cc', 23, ... ], 2 [ 'aav', 'vv', 'cc', 45, ... ], ... 15000 [ 'sad', 'ad', 'es', 123, ... ], ] I need to sort this list, but I need to specify two things: the "column"