Hi,

I have a small problem with my function: printList. I use print with a
',' . Somehow the last digit of the last number isn't printed. I wonder
why.

import random

def createRandomList(param):
    length = param

    a = []
    """" creating random list"""
    for i in range(0,length):
            a.append(random.randrange(100))
    return a

def printList(param):
    #doesn't work
    #2 sample outputs
    # 30 70 68 6 48 60 29 48 30 38
    #sorted list
    #6 29 30 30 38 48 48 60 68 7  <--- last character missing

    #93 8 10 28 94 4 26 41 72 6
    #sorted list
    #4 6 8 10 26 28 41 72 93 9 <-- dito


    for i in range(0,len(param)):
        print a[i],
   #works
   #for i in range(0,len(param)-1):
   #    print a[i],
   #print a[len(param)-1]


if __name__ == "__main__":
        length = 10
        a = createRandomList(length)
        printList(a)

        for j in range(1,len(a)):
                key = a[j]
                i = j-1
                while i > -1 and a[i]>key:
                        a[i+1] = a[i]
                        i = i-1
                a[i+1] = key
                
        print "\n sorted list"
        printList(a)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to