Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'newbie': 0.05; 'reason,': 0.07; 'suppose': 0.07; 'python': 0.11; 'random': 0.14; 'array.': 0.16; 'cards.': 0.16; 'concatenate': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'here).': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'index': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'import': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'array': 0.29; 'direction': 0.30; 'anyone': 0.31; "can't": 0.35; 'received:84': 0.35; 'but': 0.35; 'really': 0.36; 'done': 0.36; 'half': 0.37; 'two': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'moving': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'lower': 0.61; 'simple': 0.61; 'cards': 0.65; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'to,': 0.72; 'cut': 0.74; 'cards,': 0.84; 'reply-to:addr:python.org': 0.84; 'subject:Cutting': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=cIzZ7DuN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=rfTkJ7hIeaEA:10 a=gbz9piKRtqsJjw6vYiAA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Sun, 26 May 2013 19:04:52 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Cutting a deck of cards References: <4d02f46f-8264-41bf-a254-d1c20469626e@googlegroups.com> In-Reply-To: <4d02f46f-8264-41bf-a254-d1c20469626e@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369591492 news.xs4all.nl 16002 [2001:888:2000:d::a6]:60937 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46089 On 26/05/2013 18:52, RVic 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 > The list from its start up to, but excluding, index 'i' is cards[ : i], and the list from index 'i' to its end is cards[i : ]. Now concatenate them those slices.