I.laboy - 1 year ago 101
Python Question

# Python sorting algorithm

This is a coding algorithm i found in python which does not seem to work i get a name error element line 7 and a trace back line 15

the program is supposed to find the lowest number in the array and bring it into the new sorted_copy list but it seems not to work

``````def copy_sort(array):
copy=array[:]
sorted_copy=[]
while len(copy)>0:
minimum=0
for element in range(0,len(copy)):
if copy[elememt] < copy[minimum]:
minimum=element
print('\nRemoving value',copy[minimum],\
'from',copy)
sorted_copy.append(copy.pop(minimum))
return sorted_copy
array=[5,3,1,2,6,4]
print('Copy sort...\nArray:',array)
print('copy :', copy_sort(array))
print('array',array)
``````

``````def copy_sort(array):
copy=array[:]
sorted_copy=[]
while len(copy)>0:
minimum=0
for element in range(0,len(copy)):
if copy[element] < copy[minimum]:
minimum=element
print('\nRemoving value',copy[minimum], 'from',copy)
sorted_copy.append(copy.pop(minimum))
return sorted_copy

array=[5,3,1,2,6,4]
print('Copy sort...\nArray:',array)
print('copy :', copy_sort(array))
print('array',array)`
``````