我有以下字符串列表:
l1 = ['one','two','three']
我想获得一个列表,其中包含相同的元素,重复n
次。如果n=3
,则会得到:
l2 = ['one','one','one','two','two','two','three','three','three']
我所尝试的是这样的:
l2 = [3*i for i in l1]
但我得到的是这个:
l2 = ['oneoneone','twotwotwo','threethreethree']
如果我尝试这样做:
l2 = [3*(str(i)+",") for i in l1]
我得到:
l2 = ['one,one,one','two,two,two','three,three,three']
我错过了什么?
sorted(l1*3,key=l1.index)
。 - ScootCork