Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: python can you put try except in list comprehension 
Python :: how to create a spark schema using a string 
Python :: How to change application icon of pygame 
Python :: permutation in python 
Python :: explode multiple columns pandas 
Python :: create smtp server python 
Python :: python random number between 0 and 1 
Python :: how to maximize the screen in selenium 
Python :: number string array 
Python :: embeds discord.py 
Python :: 0x80370102 kali linux 
Python :: exception logging 
Python :: python slicing a list 
Python :: convert png rgba to rgb pyhton 
Python :: interface in python 
Python :: add python to zsh wsl 
Python :: Python - Comment lire une ligne de fichier par ligne 
Python :: python c like struct 
Python :: with open python print file name 
Python :: python append 
Python :: h2o ai python 
Python :: design patterns python 
Python :: django q example 
Python :: Check instance has an attribute in python 
Python :: list to one hot encoding pandas 
Python :: distribution analysis pandas 
Python :: How To Remove Elements From a Set using pop() function in python 
Python :: open python not write file 
Python :: python matplotlib pyplot set axis equals 
Python :: not intersection list python 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =