# 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.
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
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
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 know that
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.
--
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 ]
Wow,
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 :)
Updating is a
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
and
How about:
list.sort(key=lambda x: x[3])
Does that work?
--
http://mail.python.org/mailman/listinfo/python-list
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
--
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 about
11 matches
Mail list logo