P
python_newbie
I don't know this list is the right place for newbie questions. I try
to implement insertion sort in pyhton. At first code there is no
problem. But the second one ( i code it in the same pattern i think )
doesn't work. Any ideas ?
------------------------------------------------------------
def insertion_sort(aList):
for i in range(len(aList)):
for j in range(i):
if aList < aList[j]:
aList.insert(j,aList)
del aList[i+1]
if __name__ == "__main__":
MyList = [7,3,5,19,8,2,9,4,15,6,8,3,19]
insertion_sort(MyList)
print MyList
-------------------------------------------------------------
def insertion_sort(aList):
for iterator in aList:
for number in range(aList.index(iterator)):
if iterator < number:
aList.insert(aList.index(number),iterator)
del aList[aList.index(iterator)+1]
if __name__ == "__main__":
MyList = [7,3,5,19,8,2,9,4,15,6,8,3,19]
insertion_sort(MyList)
print MyList
to implement insertion sort in pyhton. At first code there is no
problem. But the second one ( i code it in the same pattern i think )
doesn't work. Any ideas ?
------------------------------------------------------------
def insertion_sort(aList):
for i in range(len(aList)):
for j in range(i):
if aList < aList[j]:
aList.insert(j,aList)
del aList[i+1]
if __name__ == "__main__":
MyList = [7,3,5,19,8,2,9,4,15,6,8,3,19]
insertion_sort(MyList)
print MyList
-------------------------------------------------------------
def insertion_sort(aList):
for iterator in aList:
for number in range(aList.index(iterator)):
if iterator < number:
aList.insert(aList.index(number),iterator)
del aList[aList.index(iterator)+1]
if __name__ == "__main__":
MyList = [7,3,5,19,8,2,9,4,15,6,8,3,19]
insertion_sort(MyList)
print MyList