repeat items in a list

beliavsky at aol.com beliavsky at aol.com
Sat Mar 26 18:12:37 EDT 2016


I can create a list that has repeated elements of another list as follows:

xx = ["a","b"]
nrep = 3
print xx
yy = []
for aa in xx:
    for i in range(nrep):
        yy.append(aa)
print yy

output:
['a', 'b']
['a', 'a', 'a', 'b', 'b', 'b']

Is there a one-liner to create a list with repeated elements?



More information about the Python-list mailing list