Beginner Question

Kevin Reeder avail at
Fri Mar 28 03:13:06 CET 2003

I'm working through the online Python beginner's guide "How to Think Like a
Computer Scientist" and am stumped on one of the exercises. A
function to shuffle cards within a class definition called Deck appears
as follows:

def shuffle(self):
    import random
    nCards = len(
    for i in range(nCards):
      j = random.randrange(i, nCards)[i],[j] =[j],[i]

The problem is to rewrite the last line without using a sequence
assignment. Everything I've thought of has the result of only inserting
the random integer j at each index which doesn't solve the problem. I'm
not really asking for the "right" answer as much as something to jog my
thought in the right direction!

If you're interested to reference the text:



More information about the Python-list mailing list