To move certain values forward in the list and sort the rest in ascending order

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

(100,20,3,40,550,6,77....100) So what do we do if we have a specific value (for example, index 2) that comes forward unconditionally and then in ascending order?


2022-09-20 16:29

2 Answers

After subtracting index 2, I think we can sort the rest except index 2 and put index 2 in the front.

2022-09-20 16:29

length = int(input()) #array length
arr = input().split() #Array input
for i in range(length):
    arr[i] = int(arr[i])
n = int(input()) #Index input
tmp = arr.pop(n)

2022-09-20 16:29

If you have any answers or tips

© 2022 pinfo. All rights reserved.