Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sort list by rule

# adapted from answer given by Stack Overflow user in the source link

my_list = list(...) # this is your list

# my_rule() is a custom function applied on elements of list that must return a number
# in this way, the "real" sorting will be performed by considering the outcome of my_rule()
# reverse: False to sort element in ascending order
rule_sorted_list = sorted(my_list, lambda x: my_rule(x), reverse = False)

# Note: if your list contains number only, then just write sorted(my_list) to sort it
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #sort #list #rule
ADD COMMENT
Topic
Name
9+7 =