On May 9, 7:49 pm, Charles Sanders <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] wrote:
> > On May 9, 1:13 am, Charles Sanders <[EMAIL PROTECTED]>
> > wrote:
> [snip]
> >> or even this monstrosity ...
>
> >> def permute2( s, n ):
> >>return [ ''.join([ s[int(i/len(s)**j)%len(s)]
> >> for
[EMAIL PROTECTED] wrote:
> On May 9, 1:13 am, Charles Sanders <[EMAIL PROTECTED]>
> wrote:
[snip]
>> or even this monstrosity ...
>>
>> def permute2( s, n ):
>>return [ ''.join([ s[int(i/len(s)**j)%len(s)]
>> for j in range(n-1,-1,-1)])
>>for i in range(len(s)**n) ]
>>
>> print "pe
On May 9, 2:41 pm, [EMAIL PROTECTED] wrote:
> On May 9, 1:13 am, Charles Sanders <[EMAIL PROTECTED]>
> wrote:
> > or even this monstrosity ...
>
> > def permute2( s, n ):
> >return [ ''.join([ s[int(i/len(s)**j)%len(s)]
> > for j in range(n-1,-1,-1)])
> >for i in range(len(s)**n)
On May 9, 1:13 am, Charles Sanders <[EMAIL PROTECTED]>
wrote:
> Michael Tobis wrote:
> > Here is the bloated mess I came up with. I did see that it had to be
> > recursive, and was proud of myself for getting it pretty much on the
> > first try, but the thing still reeks of my sorry old fortran-add
Michael Tobis wrote:
> Here is the bloated mess I came up with. I did see that it had to be
> recursive, and was proud of myself for getting it pretty much on the
> first try, but the thing still reeks of my sorry old fortran-addled
> mentality.
Recursion is not necessary, but is much, much cleare
Thanks castironpi and alex, for this:
def p(a,b):
if not b: return ['']
return [i+j for i in a for j in p(a,b-1)]
That is a thing of beauty! As usual you guys didn't disappoint.
(Validity check of alphabet removed; you didn't check for duplicate
characters.)
Here is the bloated
On May 8, 4:55 pm, [EMAIL PROTECTED] wrote:
> On May 8, 3:55 pm, James Stroud <[EMAIL PROTECTED]> wrote:
>
>
>
> > Steven D'Aprano wrote:
> > > On Tue, 08 May 2007 10:22:05 +, James Stroud wrote:
>
> > >>This takes annoying past annoying to some new level of hell to which
> > >>even satan himse
On May 8, 3:55 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> Steven D'Aprano wrote:
> > On Tue, 08 May 2007 10:22:05 +, James Stroud wrote:
>
> >>This takes annoying past annoying to some new level of hell to which
> >>even satan himself wouldn't venture.
>
> > And thank you for sharing that pi
Steven D'Aprano wrote:
> On Tue, 08 May 2007 10:22:05 +, James Stroud wrote:
>
>
>>This takes annoying past annoying to some new level of hell to which
>>even satan himself wouldn't venture.
>
>
> And thank you for sharing that piece of spam with us again. It was so much
> less enjoyable t
On Tue, 08 May 2007 10:22:05 +, James Stroud wrote:
> This takes annoying past annoying to some new level of hell to which
> even satan himself wouldn't venture.
And thank you for sharing that piece of spam with us again. It was so much
less enjoyable to see it the second time.
Seriously Ja
On Mon, 2007-05-07 at 22:20 -0700, sherry wrote:
> On May 8, 9:31 am, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
> > [snip Steven's response about a programming exercise...]
>
> [snip Sherrybove's spam about physical exercise...]
And today's award for the most conspicuous failure of the Turing
sherry wrote:
> On May 8, 9:31 am, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>> On Mon, 07 May 2007 20:45:52 -0700, Michael Tobis wrote:
>>> I have a reasonably elegant solution but it's a bit verbose (a couple
>>> dozen lines which I'll post later if there is interest). Is there some
>>> clever
Michael Tobis wrote:
> I want a list of all ordered permutations of a given length of a set
> of tokens. Each token is a single character, and for convenience, they
> are passed as a string in ascending ASCII order.
>
> For example
>
> permute("abc",2)
>
> should return ["aa","ab","ac","ba","bb"
On May 8, 12:24 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
> <[EMAIL PROTECTED]> wrote:
>
>...
>
> > def p(a,b):
> > if list( a ) != sorted( list( a ) ): raise ValueError, "String not
> > ordered."
> > if not b: return ['']
> > return [i+j for i in list(a) for j in p(a,b-1)]
<[EMAIL PROTECTED]> wrote:
...
> def p(a,b):
> if list( a ) != sorted( list( a ) ): raise ValueError, "String not
> ordered."
> if not b: return ['']
> return [i+j for i in list(a) for j in p(a,b-1)]
No need for 2/3 of the list(...) calls. sorted(a) and sorted(list(a))
will A
On May 8, 9:31 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Mon, 07 May 2007 20:45:52 -0700, Michael Tobis wrote:
> > I have a reasonably elegant solution but it's a bit verbose (a couple
> > dozen lines which I'll post later if there is interest). Is there some
> > clever Pythonism I didn't
On May 7, 11:42 pm, [EMAIL PROTECTED] wrote:
> On May 7, 11:34 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > On May 7, 10:45 pm, Michael Tobis <[EMAIL PROTECTED]> wrote:
>
> > > I want a list of all ordered permutations of a given length of a set
> > > of tokens. Each token is a single character, and for
On May 7, 11:34 pm, [EMAIL PROTECTED] wrote:
> On May 7, 10:45 pm, Michael Tobis <[EMAIL PROTECTED]> wrote:
>
>
>
> > I want a list of all ordered permutations of a given length of a set
> > of tokens. Each token is a single character, and for convenience, they
> > are passed as a string in ascendi
En Tue, 08 May 2007 01:33:51 -0300, Steven D'Aprano
<[EMAIL PROTECTED]> escribió:
> On Tue, 08 May 2007 01:21:37 -0300, Gabriel Genellina wrote:
>
>> if not sorted(values): raise ValueError("unsorted values")
>
> sorted() doesn't return a flag telling if the values are sorted, it
> returns a new
On May 7, 10:45 pm, Michael Tobis <[EMAIL PROTECTED]> wrote:
> I want a list of all ordered permutations of a given length of a set
> of tokens. Each token is a single character, and for convenience, they
> are passed as a string in ascending ASCII order.
>
> For example
>
> permute("abc",2)
>
> sh
On Tue, 08 May 2007 01:21:37 -0300, Gabriel Genellina wrote:
> if not sorted(values): raise ValueError("unsorted values")
sorted() doesn't return a flag telling if the values are sorted, it
returns a new list containing values sorted. So this line will raise an
exception only on an empty sequen
On Mon, 07 May 2007 20:45:52 -0700, Michael Tobis wrote:
> I have a reasonably elegant solution but it's a bit verbose (a couple
> dozen lines which I'll post later if there is interest). Is there some
> clever Pythonism I didn't spot?
Peering into my crystal ball, I see that your algorithm does
En Tue, 08 May 2007 00:45:52 -0300, Michael Tobis <[EMAIL PROTECTED]>
escribió:
> I want a list of all ordered permutations of a given length of a set
> of tokens. Each token is a single character, and for convenience, they
> are passed as a string in ascending ASCII order.
This is what I come,
Michael Tobis wrote:
> I want a list of all ordered permutations of a given length of a set
> of tokens. Each token is a single character, and for convenience, they
> are passed as a string in ascending ASCII order.
>
> For example
>
> permute("abc",2)
>
> should return ["aa","ab","ac","ba","bb"
I want a list of all ordered permutations of a given length of a set
of tokens. Each token is a single character, and for convenience, they
are passed as a string in ascending ASCII order.
For example
permute("abc",2)
should return ["aa","ab","ac","ba","bb","bc","ca","cb","cc"]
and permute("135
25 matches
Mail list logo