I prefer itertools.chain.from_iterable to the sum trick. >>> from itertools import chain >>> lst = list('abc') >>> list(chain.from_iterable([s]*3 for s in lst)) ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']
On Tue, Mar 29, 2016 at 5:28 PM Vito De Tullio <vito.detul...@gmail.com> wrote: > Random832 wrote: > > > How do you turn ['a', 'c', 'b'] into ['a', 'a', 'a', 'c', 'c', 'c', 'b', > > 'b', 'b']? > > >>> sum([[e]*3 for e in ['a', 'c', 'b']], []) > ['a', 'a', 'a', 'c', 'c', 'c', 'b', 'b', 'b'] > > > -- > By ZeD > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list