another puzzled newbie

Elaine Jackson elainejackson7355 at home.com
Thu Aug 28 07:09:22 CEST 2003


The analogous thing works fine in interactive mode, but when I put it in a
script, the function singlePass (below) causes a compile-time error.
(Interpret-time error? What I mean is, the message appears as soon as the shell
window opens.)  Can anybody tell me what I'm stumbling over? As a point of
historical interest, this stuff was suggested by some material in Chapter 15 of
the ibiblio tutorial at http://www.ibiblio.org/obp/thinkCSpy/chap15.htm

Peace,
EJ

def shuffleList(preshuffled):
    from random import randrange
    n=len(preshuffled)
    shuffler=[]
    for i in range(n):
        shuffler+=[randrange(i,n)]
    return shuffler

def singlePass(shuffler,preshuffled,postshuffled):
    postshuffled+=[preshuffled[shuffler[0]]
    del(preshuffled[shuffler[0]])
    del(shuffler[0])
    for i in range(len(shuffler)):
        shuffler[i]+=(-1)

def shuffle(preshuffled):
    shuffler=shuffleList(preshuffled)
    postshuffled=[]
    for i in range(len(preshuffled)):
        singlePass(shuffler,preshuffled,postshuffled)
    preshuffled=postshuffled






More information about the Python-list mailing list