Re: Specific iterator in one line

2009-06-30 Thread Bearophile
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

RE: Specific iterator in one line

2009-06-30 Thread Andreas Tawn
> -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

RE: Specific iterator in one line

2009-06-30 Thread Peter Otten
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

Re: Specific iterator in one line

2009-06-30 Thread Tim Chase
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([

Re: Specific iterator in one line

2009-06-30 Thread Paul Rubin
"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

RE: Specific iterator in one line

2009-06-30 Thread Peter Otten
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

RE: Specific iterator in one line

2009-06-30 Thread Andreas Tawn
> > > 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

RE: Specific iterator in one line

2009-06-30 Thread Andreas Tawn
> > 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,

Re: Specific iterator in one line

2009-06-30 Thread Chris Rebert
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

Re: Specific iterator in one line

2009-06-30 Thread Rhodri James
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

Re: Specific iterator in one line

2009-06-30 Thread Bruno Desthuilliers
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 :

Re: Specific iterator in one line

2009-06-30 Thread Paul Rubin
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

Re: Specific iterator in one line

2009-06-30 Thread Chris Rebert
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

Re: Specific iterator in one line

2009-06-30 Thread Filip Gruszczyński
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

Specific iterator in one line

2009-06-30 Thread 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 comprehensions, but there is an additio