I'm given a text file that resembles the following...
hello 20
world 30
i'm 50
ok 20
I'm trying to use insertion sort to arrange the numerical part of the data. My code looks like the following...
def insertion_sort():
filename = input('Enter filename: ')
lst = []
for line in open(filename):
lst.append(int(line))
print(lst)
for index in range(1,len(lst)):
value = lst[index]
leftvalue = index -1
while leftvalue >= 0 and lst[leftvalue] > value:
if value < lst[leftvalue]:
lst[leftvalue + 1] = lst[leftvalue]
lst[leftvalue] = value
leftvalue = leftvalue - 1
else:
break
return lst == insertion_sort()
I'm getting the following error...
ValueError: invalid literal for int() with base 10: 'Merchant_0 96918\n'
I have tried using float in replacement with int but I can't convert strings to floats.