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


Groups > comp.lang.python > #95433 > unrolled thread

Re: Python 3 sort() problem

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2015-08-17 15:18 +0100
Last post2015-08-17 15:18 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#95433 — Re: Python 3 sort() problem

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-08-17 15:18 +0100
SubjectRe: Python 3 sort() problem
Message-ID<mailman.60.1439821153.4764.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web