I have been searching for hours and cant find an answer to why this program is not working...its copied out of coding for beginners....sorry for so basic but be great to know why.. ....I get error message:
line 5, in bubble_sort
for element in range(len( array -1)- index):
TypeError: unsupported operand type(s) for -: 'list' and 'int'
this is the program:
def bubble_sort( array):
for index in range(len( array)):
for element in range(len( array -1)- index):
if array[ element]>array[element+1]:
array[ element], array[ element+1] = \
array[ element+1] , array[element]
print( '\tResolving element[', element,'] to' , array)
array = [5,3,1,2,6,4]
print( 'Bubble Sort...\nArray:', array)
bubble_sort(array)
print('Array:', array)
What the error message means is that you tried to subtract a number from a list.
Try
for element in range((len(array)-1) - index):
...