Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to sort and get index of sorted list in python

import numpy
# example list : [9, 3, 1, 5, 88, 22, 99] 
# make the list
my_list = numpy.array([9, 3, 1, 5, 88, 22, 99])

# for increasing order
# indexing 
index=numpy.argsort(my_list)

# sorting 
inc_list = sorted(my_list, reverse=False) 

print(inc_list,index)


# for decreasing order
# indexing 
index=numpy.argsort(-my_list)

# sorting 
dec_list = sorted(my_list, reverse=True) 

print(dec_list,index)
 
PREVIOUS NEXT
Tagged: #How #sort #index #sorted #list #python
ADD COMMENT
Topic
Name
7+7 =