Issue
>>> a = [i for i in range(3,0,-1)]
>>> a
[3, 2, 1]
>>> b = [i for i in range(3,0,-1)].sort()
>>> b
>>> c = sorted(i for i in range(3,0,-1))
>>> c
[1, 2, 3]
The b becomes None, which does not make sense.
Solution
The sort()
method operates in-place and returns None
. You must first store the list, then call sort on it. For b, you first create the list, then sort it, with the return value of sort()
being assigned to b, and the original list being lost.
Answered By - chiragzq
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.