Python Tricks

kishore Babu Valluri

6/13/20251 min read

a man riding a skateboard down the side of a ramp
a man riding a skateboard down the side of a ramp
1. Sort the list based on derived values

S=[10,-5,100,-20]

s.sort() #sorting based on given values

print(s)

Output:

-20 -5 10 100

s=[10,-5,100,-20]

s.sort(key=lambda x:x**2) # sorting based on derived values

print(s)

output:

-5 10 -20 100