repeat items in a list

Vito De Tullio vito.detullio at gmail.com
Tue Mar 29 17:25:36 EDT 2016


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




More information about the Python-list mailing list