interesting exercise

castironpi at gmail.com castironpi at gmail.com
Tue May 8 18:04:11 EDT 2007


On May 8, 4:55 pm, castiro... at gmail.com wrote:
> On May 8, 3:55 pm, James Stroud <jstr... at mbi.ucla.edu> wrote:
>
>
>
> > Steven D'Aprano wrote:
> > > On Tue, 08 May 2007 10:22:05 +0000, 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 James, with more and more people using automated spam filters,
> > > it might not be such a wise idea to keep having your name associated with
> > > spam content.
>
> > Thank you for the tip.
>
> > James
>
> We also have:
>
> p=lambda a,n: [ ''.join( y ) for y in eval('[%%s %s]'%' '.join(['for x
> %i in a'%i for i in range(n)]) %'(%s)'%','.join(['x%i'%i for i in
> range(n)]) ) ]
> p('abc',2)
> #fb: ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
> len(p('13579',3))
> #fb: 125
> edit()
>
> File under obscurities. acb

Slightly clearer:
p=lambda a,n:[ ''.join( y ) for y in eval('[(%s) %s]'%(','.join(['x
%i'%i for i in range(n)]),' '.join(['for x%i in a'%i for i in
range(n)])))]
p('abc',2)
#fb: ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc']
len(p('13579',3))
#fb: 125
edit()

where for n=4:
('[(%s) %s]'%(','.join(['x%i'%i for i in range(n)]),' '.join(['for x%i
in a'%i for i in range(n)])))
#fb: '[(x0,x1,x2,x3) for x0 in a for x1 in a for x2 in a for x3 in a]'




More information about the Python-list mailing list