Filip Gruszczyński:
> [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
I like this version (43 golf holes), it's readable enough:
[c for d in[1,0,0,1]for c in("a","bb")[d]]
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
> -Original Message-
> From: python-list-bounces+andreas.tawn=ubisoft@python.org [mailto:python-
> list-bounces+andreas.tawn=ubisoft@python.org] On Behalf Of Paul Rubin
> Sent: Tuesday, June 30, 2009 11:27 AM
> To: python-list@python.org
> Subject: Re: Specific it
Peter Otten wrote:
> Andreas Tawn wrote:
>
>>> > > This is purely sport question. I don't really intend to use the
>>> > > answer in my code, but I am wondering, if such a feat could be done.
>>> > >
>>> > > I have a following problem: I have a list based upon which I would
>>> > > like to constr
list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
50 characters. Do I win £5?
list("".join([("a","bb")[x] for x in [1,0,0,1]])
Or 49 :o)
Well, you have a missing ")" character, but that would be the
49th. You can[*] abuse python's parsing by removing certain
spaces with
list(''.join([
"Andreas Tawn" writes:
> list("".join([("a","b"*2)[x] for x in [1,0,0,1]])
> 50 characters. Do I win £5?
Er, missing right paren. Try:
list("".join(("a","bb")[x] for x in [1,0,0,1]))
--
http://mail.python.org/mailman/listinfo/python-list
Andreas Tawn wrote:
>> > > This is purely sport question. I don't really intend to use the
>> > > answer in my code, but I am wondering, if such a feat could be done.
>> > >
>> > > I have a following problem: I have a list based upon which I would
>> > > like to construct a different one. I could
> > > This is purely sport question. I don't really intend to use the answer
> > > in my code, but I am wondering, if such a feat could be done.
> > >
> > > I have a following problem: I have a list based upon which I would
> > > like to construct a different one. I could simply use list
> > > comp
> > This is purely sport question. I don't really intend to use the answer
> > in my code, but I am wondering, if such a feat could be done.
> >
> > I have a following problem: I have a list based upon which I would
> > like to construct a different one. I could simply use list
> > comprehensions,
On Tue, Jun 30, 2009 at 2:19 AM, Bruno
Desthuilliers wrote:
> Chris Rebert a écrit :
> (snip)
>
> reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1]))
>>
>> ['b', 'b', 'a', 'a', 'b', 'b']
>>
>> 69 chars long (plus or minus how the input list is written).
>
> You can save 4
On Tue, 30 Jun 2009 09:44:39 +0100, Filip Gruszczyński
wrote:
This is purely sport question. I don't really intend to use the answer
in my code, but I am wondering, if such a feat could be done.
I have a following problem: I have a list based upon which I would
like to construct a different
Chris Rebert a écrit :
(snip)
reduce(lambda x,y:x+y,({1:['b']*2,0:['a']}[z] for z in [1, 0, 0, 1]))
['b', 'b', 'a', 'a', 'b', 'b']
69 chars long (plus or minus how the input list is written).
You can save 4 more characters using tumple dispatch instead of dict
dispatch:
reduce(lambda x,y :
Filip Gruszczyäski writes:
> [1, 0, 0, 1] -> ['b', 'b', 'a', 'a', 'b', 'b']
Using itertools:
>>> list(chain(*imap([['a'],['b','b']].__getitem__, [1,0,0,1])))
['b', 'b', 'a', 'a', 'b', 'b']
--
http://mail.python.org/mailman/listinfo/python-list
2009/6/30 Filip Gruszczyński :
> This is purely sport question. I don't really intend to use the answer
> in my code, but I am wondering, if such a feat could be done.
>
> I have a following problem: I have a list based upon which I would
> like to construct a different one. I could simply use list
Oh, and there is additional requirement: it must be a one liner with
at most 80 characters ;-)
W dniu 30 czerwca 2009 10:44 użytkownik Filip Gruszczyński
napisał:
> This is purely sport question. I don't really intend to use the answer
> in my code, but I am wondering, if such a feat could be don
This is purely sport question. I don't really intend to use the answer
in my code, but I am wondering, if such a feat could be done.
I have a following problem: I have a list based upon which I would
like to construct a different one. I could simply use list
comprehensions, but there is an additio
15 matches
Mail list logo