On Tue, Jun 30, 2009 at 2:19 AM, Bruno Desthuilliers<bruno.42.desthuilli...@websiteburo.invalid> 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 more characters using tumple dispatch instead of dict > dispatch: > > reduce(lambda x,y : x+y, ((['a'], ['b']*2)[z] for z in [1, 0, 0, 1])) > >> Where's my golf trophy? ;) > > golf ? Why golf ?-)
http://en.wikipedia.org/wiki/Code_golf It's the sport the OP is playing. Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list