Sort list from a specific index value in python -


i want sort python list specific index. here want achieve. consider list al = [1,2,4,3] want is, start last index, go , swap number smaller last index, i.e 2 @ index 1. list [1,3,4,2]

but, after swapping want sort sub-list after swapped index. instead of [1,3,4,2] want [1,3,2,4] there way in python sort sub-list? right if use sort method particular index example: al[2:].sort() creates new list instead of changing same.

you use sorted() on slice , assign result slice:

al[2:] = sorted(al[2:]) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -