Below is one of the way to sort number list . Please comment if you have any doubts in below approach.
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
sorted_list
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
sorted_list
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
Below is sample code to sort in ascending order .
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
// This enables debugging.
define( ‘WP_DEBUG’, true );
Below is sample code to sort in ascending order .
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
Below is simple code to sort number list in ascending order.
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
Answers ( 8 )
Below is one of the way to sort number list . Please comment if you have any doubts in below approach.
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
sorted_list
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
sorted_list
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
Attached is the code you can use to sort array in ascending order . Please check and comment in case of any doubts
Below is sample code to sort in ascending order .
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
// This enables debugging.
define( ‘WP_DEBUG’, true );
Below is sample code to sort in ascending order .
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
Below is simple code to sort number list in ascending order.
num_list = [2,5,1,7,8]
sorted_list = []
while num_list:
min_num = num_list[0] # taking first element as minimum
for element in num_list: # loop through all elements
if element < min_num:
min_num = element
sorted_list.append(min_num) # append minimum element
num_list.remove(min_num) # remove it from original list
print(sorted_list)
D = [2,5,1,7,8]
D.sort()