newbie question

Justin Shaw wyojustin at hotmail.com
Sat Dec 14 12:47:12 EST 2002


I think you have the bubble sort wrong.  To run the debugger:
>>> import pdb
>>> pdb.run('reload test')

type help for a list of commands.

Justin

ps I added some debug prints and got the following result.

a=[('a',1),('c',5),('k',5),('o',3), ('i',3)]
for i in range(0, len(a)-1):
    for j in range(1, len(a)):
        if a[i][1]>a[j][1]:
            print a
            print '    swap', i, j, a[i], a[j]
            a[i],a[j]=a[j],a[i]
            print '   ', a
print a

RESULT:
[('a', 1), ('c', 5), ('k', 5), ('o', 3), ('i', 3)]
    swap 1 3 ('c', 5) ('o', 3)
    [('a', 1), ('o', 3), ('k', 5), ('c', 5), ('i', 3)]
[('a', 1), ('o', 3), ('k', 5), ('c', 5), ('i', 3)]
    swap 2 1 ('k', 5) ('o', 3)
    [('a', 1), ('k', 5), ('o', 3), ('c', 5), ('i', 3)]
[('a', 1), ('k', 5), ('o', 3), ('c', 5), ('i', 3)]
    swap 3 2 ('c', 5) ('o', 3)
    [('a', 1), ('k', 5), ('c', 5), ('o', 3), ('i', 3)]
[('a', 1), ('k', 5), ('c', 5), ('o', 3), ('i', 3)]







More information about the Python-list mailing list