Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36186 > unrolled thread

Random List Loop?!

Started byChristian Gabriel <gabrieldenmark@gmail.com>
First post2013-01-05 07:47 -0800
Last post2013-01-05 16:02 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Random List Loop?! Christian Gabriel <gabrieldenmark@gmail.com> - 2013-01-05 07:47 -0800
    Re: Random List Loop?! Roy Smith <roy@panix.com> - 2013-01-05 10:54 -0500
    Re: Random List Loop?! Chris Angelico <rosuav@gmail.com> - 2013-01-06 02:59 +1100
    Re: Random List Loop?! Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-01-05 16:02 +0000

#36186 — Random List Loop?!

FromChristian Gabriel <gabrieldenmark@gmail.com>
Date2013-01-05 07:47 -0800
SubjectRandom List Loop?!
Message-ID<ce887da5-1fad-49af-85e3-96ca41b7148c@googlegroups.com>
Hi

I have tried now for ages to make a loop that does the following:

Makes a new list with 9 random values, from 9 different lists, with 9 elements.

And makes sure that none of the elements repeat! 

Is there anyone that can help, with a very simple solution??

Best

Christian

[toc] | [next] | [standalone]


#36187

FromRoy Smith <roy@panix.com>
Date2013-01-05 10:54 -0500
Message-ID<roy-5B9BB0.10543905012013@news.panix.com>
In reply to#36186
In article <ce887da5-1fad-49af-85e3-96ca41b7148c@googlegroups.com>,
 Christian Gabriel <gabrieldenmark@gmail.com> wrote:

> Hi
> 
> I have tried now for ages to make a loop that does the following:
> 
> Makes a new list with 9 random values, from 9 different lists, with 9 
> elements.
> 
> And makes sure that none of the elements repeat! 
> 
> Is there anyone that can help, with a very simple solution??
> 
> Best
> 
> Christian

You want random.sample()

http://docs.python.org/2/library/random.html#random.sample

[toc] | [prev] | [next] | [standalone]


#36190

FromChris Angelico <rosuav@gmail.com>
Date2013-01-06 02:59 +1100
Message-ID<mailman.128.1357401564.2939.python-list@python.org>
In reply to#36186
On Sun, Jan 6, 2013 at 2:47 AM, Christian Gabriel
<gabrieldenmark@gmail.com> wrote:
> Hi
>
> I have tried now for ages to make a loop that does the following:
>
> Makes a new list with 9 random values, from 9 different lists, with 9 elements.
>
> And makes sure that none of the elements repeat!
>
> Is there anyone that can help, with a very simple solution??

Sounds like a homework question to me.

You've tried. What code have you come up with, and to what extent does
it fall short of your goal?

The nine different lists - do they have unique elements?

Are you able to use sets? (If you haven't been taught what a set is,
the answer's probably no.)

ChrisA

[toc] | [prev] | [next] | [standalone]


#36192

FromOscar Benjamin <oscar.j.benjamin@gmail.com>
Date2013-01-05 16:02 +0000
Message-ID<mailman.130.1357401741.2939.python-list@python.org>
In reply to#36186
On 5 January 2013 15:47, Christian Gabriel <gabrieldenmark@gmail.com> wrote:
> Hi
>
> I have tried now for ages to make a loop that does the following:
>
> Makes a new list with 9 random values, from 9 different lists, with 9 elements.
>
> And makes sure that none of the elements repeat!
>
> Is there anyone that can help, with a very simple solution??

I'm sure that there is a simple solution but I don't fully understand
your problem could you perhaps provide an example with actual numbers
(perhaps use 3 instead of 9 so it's easier to follow)?

In any case I suspect that you want something involving range() and
random.shuffle() if that helps.


Oscar

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web