Iain King wrote:
> or shorter but possible less readable (and only in 2.4+):
>
> def shuffle(data):
> return [y[1] for y in sorted([(random(), x) for x in data])]
sorted() and list.sort() will happily accept a key function argument and
then do the decorating/undecorating for you:
>>> from r
David C. Ullrich wrote:
> On 30 May 2006 21:53:32 -0700, "greenflame" <[EMAIL PROTECTED]>
> wrote:
>
> That's DSU for _sorting_ a list. I read about this, thought
> it was pretty neat. I thought that the fact that you
> could use the same trick for _shuffling_ a list was
> my idea, gonna make me r
On Thu, 01 Jun 2006 03:25:23 -0700, Erik Max Francis <[EMAIL PROTECTED]>
wrote:
>David C. Ullrich wrote:
>
>> Good example, because we know that EMF is not dumb. I've seen
>> the same algorithm many times - the best example is ...
>
>Man, an error made _six years ago_ and people are still bringing
Peter Otten <[EMAIL PROTECTED]> wrote:
> Gerard Flanagan wrote:
> > Ben Finney wrote:
>
> >> pile_index = 0
> >> for card in deck:
> >> piles[pile_index].append(card)
> >> pile_index = (pile_index + 1) % numpiles
> >
> > no need to maintain an index ;-)
>
Peter Otten wrote:
> Gerard Flanagan wrote:
>
> > Ben Finney wrote:
>
> >> pile_index = 0
> >> for card in deck:
> >> piles[pile_index].append(card)
> >> pile_index = (pile_index + 1) % numpiles
> >>
> >
> > no need to maintain an index ;-)
> >
> > pi
David C. Ullrich wrote:
> Good example, because we know that EMF is not dumb. I've seen
> the same algorithm many times - the best example is ...
Man, an error made _six years ago_ and people are still bringing it up ...
--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
Sa
On Wed, 31 May 2006 23:05:14 +0200, Fredrik Lundh
<[EMAIL PROTECTED]> wrote:
>Roger Miller wrote:
>
>> DSU seems like a lot of trouble to go through in order to use an O(n
>> log n) sorting algorithm to do what can be done in O(N) with a few
>> lines of code. The core code of random.shuffle() sho
Gerard Flanagan wrote:
> Ben Finney wrote:
>> pile_index = 0
>> for card in deck:
>> piles[pile_index].append(card)
>> pile_index = (pile_index + 1) % numpiles
>>
>
> no need to maintain an index ;-)
>
> piles = [ list() for _ in range(n) ]
>
"Gerard Flanagan" <[EMAIL PROTECTED]> writes:
> Ben Finney wrote:
> > pile_index = 0
> > for card in deck:
> > piles[pile_index].append(card)
> > pile_index = (pile_index + 1) % numpiles
> >
>
> no need to maintain an index ;-)
>
> piles = [ list()
Ben Finney wrote:
[snip]
>
> Please don't write C in Python. The 'for' statement allows iteration
> directly over a sequence, no need to maintain an index. Also, the
> modulus operator is called for with your cycling of the pile index.
>
> pile_index = 0
> for card in deck:
>
Roger Miller wrote:
> DSU seems like a lot of trouble to go through in order to use an O(n
> log n) sorting algorithm to do what can be done in O(N) with a few
> lines of code. The core code of random.shuffle() shows how easy it is
> to do it right:
>
> for i in reversed(xrange(1, len(x)
Sybren Stuvel wrote:
> David C Ullrich enlightened us with:
> > I thought that the fact that you could use the same trick for
> > _shuffling_ a list was my idea, gonna make me rich and famous. I
> > guess I'm not the only one who thought of it. Anyway, you can use
> > DSU to _shuffle_ a list by de
On Wed, 31 May 2006 12:17:11 +0200, Sybren Stuvel
<[EMAIL PROTECTED]> wrote:
>David C Ullrich enlightened us with:
>> I thought that the fact that you could use the same trick for
>> _shuffling_ a list was my idea, gonna make me rich and famous. I
>> guess I'm not the only one who thought of it.
David C Ullrich enlightened us with:
> I thought that the fact that you could use the same trick for
> _shuffling_ a list was my idea, gonna make me rich and famous. I
> guess I'm not the only one who thought of it. Anyway, you can use
> DSU to _shuffle_ a list by decorating the list with random n
greenflame wrote:
> Zhang Fan wrote:
>> On 30 May 2006 20:18:19 -0700, greenflame <[EMAIL PROTECTED]> wrote:
>>> Second of all, I would like to have
>>> other methods of shuffling, prefererably riffle shuffling and just
>>> plain randomly arranging the elements of the list.
>> The random module has
On 30 May 2006 21:53:32 -0700, "greenflame" <[EMAIL PROTECTED]>
wrote:
>Thank you all for all of your help. Also I got the shuffle function to
>work. Do not worry I will be back soon with more shuffling! However, I
>do not quite understand this DSU that you mention, although it looks
>useful.
I d
Thank you all for all of your help. Also I got the shuffle function to
work. Do not worry I will be back soon with more shuffling! However, I
do not quite understand this DSU that you mention, although it looks
useful.
--
http://mail.python.org/mailman/listinfo/python-list
greenflame wrote:
> Zhang Fan wrote:
>> ... The random module has a `shuffle' method. It "Shuffle the sequence x
>> in place". It may be help for you
>
> I am sorry but this does not help much. In my version of python (2.3)
> this method does not seem to exist. Also from the documentation, it
>
On 31/05/2006 1:18 PM, greenflame wrote:
> I would like to make a function that takes a list, more specificaly a
> list of strings, and shuffles its elements, like a pile of cards. The
> following is a script I tryed to make that implements pile shuffling.
>
In general, if you can't see why Pytho
"greenflame" <[EMAIL PROTECTED]> writes:
> I would like to make a function that takes a list, more specificaly a
> list of strings, and shuffles its elements, like a pile of cards.
Sounds like a job for (ta-da-daa) DSU[0].
That said, here are some comments on your implementation.
> --
>
Zhang Fan wrote:
> On 30 May 2006 20:18:19 -0700, greenflame <[EMAIL PROTECTED]> wrote:
> > Second of all, I would like to have
> > other methods of shuffling, prefererably riffle shuffling and just
> > plain randomly arranging the elements of the list.
>
> The random module has a `shuffle' method.
On 30 May 2006 20:18:19 -0700, greenflame <[EMAIL PROTECTED]> wrote:
> Second of all, I would like to have
> other methods of shuffling, prefererably riffle shuffling and just
> plain randomly arranging the elements of the list.
The random module has a `shuffle' method. It "Shuffle the sequence
I would like to make a function that takes a list, more specificaly a
list of strings, and shuffles its elements, like a pile of cards. The
following is a script I tryed to make that implements pile shuffling.
--
testdeck = list('qwertyuiop')
def pileshuffle(DECK, NUMPILES):
"""Split
23 matches
Mail list logo