"list index out of range" error
sam
python.sam at googlemail.com
Wed Sep 20 18:39:32 EDT 2006
for what it's worth. and it is approx. five times quicker than the
bubblesort i wrote to begin with on a 286-word highly unordered list,
so i wasn't wasting my time after all...
______________________________________________________________________
import time
file_input = open('wordlist.txt', 'r')
list_initial = []
no_lines = 0
for line in file_input:
list_initial.append(line)
no_lines += 1
no_lines_2 = no_lines
print list_initial
file_input.close()
raw_input('press enter to sort: ')
list_final = []
temp_str = ""
time1 = time.clock()
for j in range(no_lines_2):
temp_str = 'zzzzzzzzzzzzzzzzzz'
for k in range(no_lines):
if temp_str > list_initial[k]:
temp_str = list_initial[k]
list_initial.remove(temp_str)
list_final.append(temp_str)
no_lines -= 1
time2 = time.clock()
final_time = time2 - time1
print list_final
print
print 'number of seconds for sort list: ', final_time
print
print 'number of words in list: ', no_lines_2
___________________________________________________________________
thanks again for your help. that sorted out something that had really
been bugging me.
More information about the Python-list
mailing list