-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorting_algorithm.py
33 lines (25 loc) · 950 Bytes
/
sorting_algorithm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def sort():
array_size = 80
input_list = [23,2,43,12,9,1,4,54,65,23]
array = ['*' for _ in range(array_size)] # Create a array with specified range with special character
for num in input_list:
array[num] = num # Modified the array, with adding the number in the list with the same index value of the number itself
#You can do this process downin three ways
#FIRST WAY
sort = []
for i in array:
if i != '*': # Checking whether it is a special character or a number
sort = sort + [i] # added the numbers in a new list while removing the special character so we get the sorted list
"""
#SECOND WAY
sort = [i for i in array if i != '*']
#THRID WAY
for i in array:
if i != '*':
sort.append(i)
#OR
sort += [i]
"""
print(f"Your List : {input_list}")
print(f"Sotred List: {sort}")
sort()