Beginner Question
Kevin Reeder
avail at uponrequest.org
Fri Mar 28 01:49:40 EST 2003
On Thu, 27 Mar 2003 20:45:04 -0800, Lee Harr wrote:
> Well... it is not just the last line, but I think the best way would be:
>
> import random
> def shuffle(self):
> random.shuffle(self.cards)
This one failed to work with the exception: Attribute error: shuffle.
Probably something I'm not seeing.
>
>
> How about this:
>
> def shuffle(self):
> import random
> nCards = len(self.cards)
> for i in range(nCards):
> j = random.randrange(i, nCards)
> self.cards.insert(i, self.cards.pop(j))
This solution worked great. Is insert a list method?
Kevin
More information about the Python-list
mailing list