Cutting a deck of cards
Roy Smith
roy at panix.com
Sun May 26 14:21:29 EDT 2013
More information about the Python-list mailing list
Sun May 26 14:21:29 EDT 2013
- Previous message (by thread): Cutting a deck of cards
- Next message (by thread): Cutting a deck of cards
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <4d02f46f-8264-41bf-a254-d1c20469626e at googlegroups.com>, RVic <rvince99 at gmail.com> wrote: > Suppose I have a deck of cards, and I shuffle them > > import random > cards = [] > decks = 6 > cards = list(range(13 * 4 * decks)) > random.shuffle(cards) > > So now I have an array of cards. I would like to cut these cards at some > random point (between 1 and 13 * 4 * decks - 1, moving the lower half of that > to the top half of the cards array. > > For some reason, I can't see how this can be done (I know that it must be a > simple line or two in Python, but I am really stuck here). Anyone have any > direction they can give me on this? Thanks, RVic, python newbie import random i = random.randrange(len(cards)) cut1 = cards[:i] cut2 = cards[i:] I haven't thought too much about the boundary conditions, but that's the general idea.
- Previous message (by thread): Cutting a deck of cards
- Next message (by thread): Cutting a deck of cards
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list