Sort a list in python

后端 未结 3 887
执念已碎
执念已碎 2020-12-03 11:30

I have this list

[1,-5,10,6,3,-4,-9]

But now I want the list to be sorted like this:

[10,-9,6,-5,-4,3,1]

3条回答
  •  孤城傲影
    2020-12-03 12:05

    I was searching this and wanted to add my solution: This is how you can create 2D array with (x,f(x)) values in sorted order.

    #Create 30 random number between 0 and 1
    k = np.random.random ((30,2)) 
    k= np.sort(k,0) #sort x values
    for i in range(len(k[:])):
        k[i][1] = f(k[i][0])
    

提交回复
热议问题