Suppose I have a list,
lst = [5, 3, 5, 1, 4, 7]
and I want to get it ordered from the second element 3 to the end.
I thought I could do it by:
lst[1:].sort()
But, this doesn't work.
How can I do it?
lst = lst[0:1] + sorted(lst[1:])
lst = [5, 3, 5, 1, 4, 7]
lst[1:] = sorted(lst[1:])
print(lst) # prints [5, 1, 3, 4, 5, 7]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With