[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 "permute2('abc',2) =", permute2('abc',2)
>> print "len(permute2('13579',3)) =", len(permute2('13579',3))
>>
>> permute2('abc',2) = ['aa', 'ab', 'ac', 'ba', 'bb', 'bc',
>>   'ca', 'cb', 'cc']
>> len(permute2('13579',3)) = 125
>>
>> Charles
> 
> Could you explain, this one, actually?  Don't forget StopIteration.
> 

        As Michael said, simple counting in base n with the
string as the digits. No attempt at clarity or efficiency (I
did say it was a "monstrosity").

        Also, as a python beginner I didn't know about divmod,
and have no idea what you (castironpi) mean by "Don't forget
StopIteration."


Charles
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to