how to sort a list from highest to lowest in python code example
Example 1: python sort list in reverse
list.sort(reverse=True)
sorted(list, reverse=True)
Example 2: how to sort a list descending python
A.sort(reverse = True)
Example 3: how to manually sort a list in python
Numbers = []
iterate = 0
while len(Numbers)<5:
try:
x = int(input("Insert the number you want in the list: "))
Numbers.append(x)
except:
print("The input MUST be a number.")
continue
for iteration_count in range(len(Numbers)):
for j in range(0,len(Numbers)-1):
if (Numbers[j]>Numbers[j+1]):
Numbers[j],Numbers[j+1] = Numbers[j+1],Numbers[j]
print(f"Here are the sorted numbers:{Numbers}")
Example 4: python sort list
vowels = ['e', 'a', 'u', 'o', 'i']
vowels.sort()
Example 5: how to sort a list in python
l=[1,3,2,5]
l= sorted(l)
print(l)
l=[1,3,2,5]
l= sorted(l,reverse=True)
print(l)
Example 6: python how to find the highest even in a list
def highest_even(li):
evens = []
for item in li:
if item % 2 == 0:
evens.append(item)
return max(evens)
print(highest_even([10,2,3,4,8,11]))