Sometimes, we want to create list of single item repeated N times with Python.
In this article, we’ll look at how to create list of single item repeated N times with Python.
How to create list of single item repeated N times with Python?
To create list of single item repeated N times with Python, we can use the *
operator.
For instance, we write
l = [5] * 4
to create the list l
with 4 5’s in it.
Conclusion
To create list of single item repeated N times with Python, we can use the *
operator.