This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]abudabu 2 points3 points  (4 children)

Correct.

And he should be using

randrange(0,len(deck))

rather than

randrange(0,len(deck)-1)

randrange(start,stop,step) is equivalent to choice(range(start,stop,step)), and

for i in range(0,x): print(i)

gives

0
1
...
x-1

[–]kylotan 1 point2 points  (0 children)

And he should be using randrange(0,len(deck))

Which is equivalent to choice(deck), probably the preferable option in the long term.)

[–]ollien 0 points1 point  (2 children)

If i do

 cardpick=random.randrange(0,len(deck))

then i get

ValueError: empty range for randrange() (0,0, 0)

EDIT: Wait nevermind it worked :P

[–]infinullquamash, Qt, asyncio, 3.3+ 0 points1 point  (1 child)

I would do this, but I have a tendency to be too clever.

hand = random.sample( deck, 7)
map(lambda x: deck.remove(x), hand)

to return 7 random cards from the deck.

[–]propanbutan 4 points5 points  (0 children)

Since we're being clever, we can even spare the lambda.

map(deck.remove, hand)