To start with, if one has a list = [a, b, c]
, if one prints it, one will get the following error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-17-eb02c90df247> in <module>
----> 1 list = [a, b, c]
2 list
NameError: name 'c' is not defined
The list
should be defined as follows
>>> list = ['a', 'b', 'c']
>>> print(list)
['a', 'b', 'c']
For your case, simply multiplying the list with N will do the work. For the examples, let's consider N=3
>>> n = 3
>>> list = list*n
['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
Now, and giving an alternative answer, as the need may arise, if one wants to extend the list (considering, for the example, N=3) as follows
['a' 'a' 'a' 'b' 'b' 'b' 'c' 'c' 'c']
One can use np.repeat
do that
>>> n = 3
>>> list= np.repeat(list, n)
array(['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'], dtype='<U1')
This retrieved an array. If that doesn't fit one's needs and one wants a list (use np.ndarray.tolist
), as follows
>>> list = list.tolist()
['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']