Reputation: 67
I would like to append append an item more than once. e.g
listA = ['AS','23','45']
listB = ['TH','67','78']
listB.append(listA.pop()*3)
print(listA)
# ['AS', '23']
print(listB)
#['TH', '67', '78', '454545']
on printing listB, it currently gives me the above list
but i want it to give me # ['TH', '67', '78', '45','45','45']
instead
How can i do this.
Upvotes: 1
Views: 676
Reputation: 95358
Try using list.extend()
and repeating not the string returned by pop()
, but a single-element list:
>>> listA = ['AS','23','45']
>>> listB = ['TH','67','78']
>>> listB.extend([listA.pop()]*3)
>>> listB
['TH', '67', '78', '45', '45', '45']
Upvotes: 7