Creating a list in Python with multiple copies of a given object in a single line.
- by Deniz
Suppose I have a given Object (a string "a", a number - let's say 0, or a list ['x','y'] )
I'd like to create list containing many copies of this object, but without using a for loop:
L = ["a", "a", ... , "a", "a"]
or
L = [0, 0, ... , 0, 0]
or
L = [['x','y'],['x','y'], ... ,['x','y'],['x','y']]
I'm especially interested in the third case.
Thanks!