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
--
https://mail.python.org/mailman/listinfo/python-list