Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95433

Re: Python 3 sort() problem

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Python 3 sort() problem
Date 2015-08-17 15:18 +0100
References <006601d0d8e1$c17c1480$44743d80$@inbox.ru>
Newsgroups comp.lang.python
Message-ID <mailman.60.1439821153.4764.python-list@python.org> (permalink)

Show all headers | View raw


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 it would be returned x
> that was sorted. Why so?/

A set is created from x.  This is converted to a list.  You call sort() 
and assign the return value from that, None, to x.  You will see exactly 
the same thing above if you do:-

x = x.sort()

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python 3 sort() problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-17 15:18 +0100

csiph-web