with python sort numbers in an array in ascending code example
Example 1: python sort list
# sort() will change the original list into a sorted list
vowels = ['e', 'a', 'u', 'o', 'i']
vowels.sort()
# Output:
# ['a', 'e', 'i', 'o', 'u']
# sorted() will sort the list and return it while keeping the original
sortedVowels = sorted(vowels)
# Output:
# ['a', 'e', 'i', 'o', 'u']
Example 2: sort array not in place python
# sorting lists in python
l = [2, 3, 1, 4]
new_l = sorted(l) # returns sorted list without modifying original
l.sort() # sorts list inplace