sort list of numbers python code example
Example 1: sort list of numbers python
nums = [48, 35, 32, 5, 5, 16, 5, 16, 28, 29] # Makes a list of numbers
sortedNums = sorted(nums, key=int) # Sorts the numbers and saves it as a variable
print(sortedNums) # Prints the variable
Example 2: get list number python
my_list = [1,"hello world", 16.2]
len(my_list)
3
Example 3: how to store sorted list into new variable in python
>>> numbers = [6, 9, 3, 1]
>>> numbers_sorted = sorted(numbers)
>>> numbers_sorted
[1, 3, 6, 9]
>>> numbers
[6, 9, 3, 1]
Example 4: python list prime numbers
print([i for i in range(2, int(input("Enter your number: "))+1) if 0 not in [i%n for n in range(2, i)]])
Example 5: how to use sorted function in python
var_array = [5,2,4,3,1]
var_sort = sorted(var_array)
Example 6: sort list in python
List_name.sort()
This will sort the given list in ascending order.