I want to create a series of lists, all of varying lengths. Each list will contain the same element e, repeated n times (where n = len
e
n
>>> [5] * 4 [5, 5, 5, 5]
Be careful when the item being repeated is a list. The list will not be cloned: all the elements will refer to the same list!
>>> x=[5] >>> y=[x] * 4 >>> y [[5], [5], [5], [5]] >>> y[0][0] = 6 >>> y [[6], [6], [6], [6]]