How Do I Sort List In Python

[Solved] How Do I Sort List In Python | Haskell - Code Explorer | yomemimo.com
Question : how to sort a list in python

Answered by : simthegreat

l=[1,3,2,5]
l= sorted(l)
print(l)
#output=[1, 2, 3, 5]
#or reverse the order:
l=[1,3,2,5]
l= sorted(l,reverse=True)
print(l)
#output=[5, 3, 2, 1]

Source : | Last Update : Sat, 11 Jul 20

Question : sort list python

Answered by : david-cao

>>> L = ['abc', 'ABD', 'aBe']
>>> sorted(L, key=str.lower, reverse=True) # Sorting built-in
['aBe', 'ABD', 'abc']
>>> L = ['abc', 'ABD', 'aBe']
>>> sorted([x.lower() for x in L], reverse=True)
['abe', 'abd', 'abc']

Source : https://www.howtouselinux.com/post/sort-list-in-python | Last Update : Mon, 28 Feb 22

Question : how to sort a list

Answered by : sparkling-salmon-n0rria8192us

prime_numbers = [11, 3, 7, 5, 2]
# sort the list
prime_numbers.sort()
print(prime_numbers)
# Output: [2, 3, 5, 7, 11]

Source : https://www.programiz.com/python-programming/methods/list/sort | Last Update : Wed, 02 Mar 22

Question : sort list in python

Answered by : natural-morons

l = [64, 25, 12, 22, 11, 1,2,44,3,122, 23, 34]
for i in range(len(l)): for j in range(i + 1, len(l)): if l[i] > l[j]: l[i], l[j] = l[j], l[i]
print l

Source : https://stackoverflow.com/questions/11964450/python-order-a-list-of-numbers-without-built-in-sort-min-max-function | Last Update : Tue, 10 May 22

Question : sort a list python

Answered by : odunosho-moses

"""Sort in ascending and descending order"""
list_test = [2, 1, 5, 3, 4]
#ascending is by default for sort
#Time Complexity: O(nlogn)
list_test.sort()
#For descending order
#Time Complexity: O(nlogn)
list_test.sort(reverse=True)
#For user-define order
list_test.sort(key=..., reverse=...) 

Source : | Last Update : Tue, 12 Jul 22

Question : sort list in python

Answered by : natural-morons

data_list = [-5, -23, 5, 0, 23, -6, 23, 67]
new_list = []
while data_list: minimum = data_list[0] # arbitrary number in list for x in data_list: if x < minimum: minimum = x new_list.append(minimum) data_list.remove(minimum)
print new_list

Source : https://stackoverflow.com/questions/11964450/python-order-a-list-of-numbers-without-built-in-sort-min-max-function | Last Update : Tue, 10 May 22

Answers related to how do i sort list in python

Code Explorer Popular Question For Haskell