FAQ

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 sort() returns None, but I guess that it would be returned x that was sorted. Why so?


?

Maybe you want sorted?
x = [4,2,1,3]
sorted(x)
[1, 2, 3, 4]


[The list(set(..)) is probably for removing duplicates. Right?
Which you seem to have worked out it seems?
So best when asking questions to focus on one issue at a time]

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 5 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedAug 17, '15 at 11:42a
activeAug 17, '15 at 2:28p
posts5
users5
websitepython.org

People

Translate

site design / logo © 2018 Grokbase