The ideal way is probably numpy.repeat:

In [16]:

import numpy as np  
x1=[1,2,3,4]
In [17]:

np.repeat(x1,3)
Out[17]:
array([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4])
Answer from CT Zhu on Stack Overflow
🌐
FavTutor
favtutor.com › blogs › repeat-n-times-python
How to Repeat N times in Python? (& how to Iterate?)
October 25, 2022 - ... The above syntax might not result in anything for you. The repeat() function actually repeats the value n times into a list, hence the obtained output needs to be stored in a list in order to be displayed.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-element-repetition-in-list
Python - Repeat a element in a List - GeeksforGeeks
July 11, 2025 - In this example, list comprehension iterates through the list 'a' and repeats each element twice. The itertools.chain() function is typically used to combine iterables.
Discussions

python - Repeating elements of a list n times - Stack Overflow
How do I repeat each element of a list n times and form a new list? For example: Copyx = [1,2,3,4] n = 3 x1 = [1,1,1,2,2,2,3,3,3,4,4,4] ... There must be a simple and smart way. ... Related questions: Circular list iterator in Python, Duplicate elements in a list, Repeat a list within a list ... More on stackoverflow.com
🌐 stackoverflow.com
python - Create list of single item repeated N times - Stack Overflow
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 = length of the list). How do I create the lists, without using a list More on stackoverflow.com
🌐 stackoverflow.com
function to find repeating numbers in list
def find_duplicates(numbers): seen = set(); duplicates = set() for number in numbers: if number in seen: duplicates.add(number) else: seen.add(number) return sorted(duplicates) More on reddit.com
🌐 r/learnpython
6
5
December 18, 2023
Repeat function
You’re looking for “while”, which is introduced in the official tutorial here . I highly recommend you read the whole tutorial, as it’s quite good at teaching the basics. More on reddit.com
🌐 r/learnpython
2
2
May 17, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-repeat-each-element-k-times-in-list
Repeat Each Element K times in List - Python - GeeksforGeeks
July 11, 2025 - Explanation: List comprehension repeat each element in a . It iterates over a and for each element i, it appends i to the result k times, efficiently creating the repeated list. ... itertools module offers a powerful way to handle repetitive ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.repeat.html
numpy.repeat — NumPy v2.5 Manual
Repeat each element of an array after themselves · The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis
🌐
Finxter
blog.finxter.com › python-repeat-list-n-times
Python Repeat List N Times – Be on the Right Side of Change
July 17, 2023 - In conclusion, you can use either the for loop or the * operator method to repeat elements of a list N times in Python.
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › python › python repeat n times
How to Repeat Code N Times in Python | Delft Stack
February 14, 2024 - In this article, we’ve explored five methods to repeat a string of code N times in Python: using for loops, while loops, the itertools.repeat() function, list comprehension, and recursion.
🌐
Enki
enki.com › post › how-to-repeat-code-in-python
Enki | Blog - How to Repeat Code in Python
Repeating code in Python using for loops is both powerful and simple, making your code more readable and maintainable. You can iterate over various data structures such as lists, tuples, and dictionaries, or simply repeat an action using the range() function.
🌐
Java2Blog
java2blog.com › home › python › python list › repeat list n times in python
Repeat List N Times in Python [4 Ways] - Java2Blog
December 26, 2022 - In the above example, we demonstrate the use of the * operator to repeat list n times in Python. This will repeat the elements of the list the required number of times. ... Use the numpy.repeat() function to repeat every element n times in Python.
🌐
TutorialsPoint
tutorialspoint.com › article › add-similar-value-multiple-times-in-a-python-list
Add similar value multiple times in a Python list
January 2, 2020 - This is the most straightforward method. The * operator creates a new list by repeating elements a specified number of times. ... The itertools.repeat() function creates an iterator that returns the same value repeatedly.
🌐
Quora
quora.com › How-do-I-repeat-a-function-in-Python
How to repeat a function in Python - Quora
Answer (1 of 8): I’m not sure what exactly you mean by “repeat”. If we define a function, it usually means that we want to use that code more than once. When we use a previously defined function, we say that we “call” the function. Functions may be called from just about anywhere ...
🌐
OpenClassrooms
openclassrooms.com › en › courses › 6902811-learn-python-basics › 7090826-easily-repeat-tasks-using-loops
Easily Repeat Tasks Using Loops - OpenClassrooms
To loop through a set of code a certain number of times, you can use the range() function, which returns a list of numbers starting from 0 to the specified end number. You haven't learned about functions yet, but you will soon!
🌐
Quora
quora.com › How-do-you-repeat-each-element-in-a-list-Python-list-development
How to repeat each element in a list (Python, list, development) - Quora
RelatedHow do you remove repeated numbers from a list in Python (Python, Python 3.x, Lista, and Development)? ... Trainee Engineer at NHPC Limited, Govt. of India (2025–present) · 2y ... You can use both loops or reduce function to multiply the elements of the list, the code using reduce ...
🌐
Python Guides
pythonguides.com › use-the-repeat-function-in-python
How To Use The Repeat() Function In Python?
March 19, 2025 - The repeat() function in Python’s module allows you to create an iterator that repeats an object a specified number of times or infinitely.
🌐
YouTube
youtube.com › pixegami
Learn Python • #6 Loops • How to Repeat Code Execution - YouTube
Loops in Python will let you run the same code over and over again.This is useful when working with lists, or if you have something that you want to execute ...
Published   April 1, 2023
🌐
Reddit
reddit.com › r/learnpython › function to find repeating numbers in list
r/learnpython on Reddit: function to find repeating numbers in list
December 18, 2023 -

Hello to everyone! We had programming test today and one of the tasks was to write function which can find duplicate numbers in lists. I wrote something like this and it was OK:

def seznam_duplicit(spisok: int): seznam_duplicit = [] for cislo1 in spisok: spisok.remove(cislo1) for cislo2 in spisok: if cislo1 == cislo2: if cislo1 not in seznam_duplicit: seznam_duplicit.append(cislo1) return(seznam_duplicit)

But now I’m trying it on my VS code and when I put up list [1, 2, 4, 5, 3, 2, 4, 1] it returns list [1, 4]. So it lost 2. I’ve tried other lists and it always looses one duplicate number. What can I do to fix this?

🌐
Reddit
reddit.com › r/learnpython › repeat function
r/learnpython on Reddit: Repeat function
May 17, 2023 -

Hi, I am very new to python and my current problem is that I want to be able to repeat a certain line of code and not the entire program until something else becomes true, I've done some digging online and cant find a solution that I understand properly, the code pasted has a comment on line 22, that is where I want a repeat function to go, the comment goes more in-depth. Here is a link to the code

https://pastebin.com/M46X2awm

🌐
The Carpentries
carpentries-incubator.github.io › python-novice-programming-gapminder › 05-loop › index.html
Repeating Actions with Loops – Programming with Python
May 20, 2025 - This is shorter — certainly shorter than something that prints every number in a hundred-number list — and more robust as well: odds = [1, 3, 5, 7, 9, 11] for num in odds: print(num) ... The improved version uses a for loop to repeat an operation — in this case, printing — once for each thing in a sequence.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-itertools-repeat
Python - itertools.repeat() - GeeksforGeeks
July 12, 2025 - # Python code to demonstrate the working of # repeat() import itertools # using repeat() to repeatedly print number print ("Printing the numbers repeatedly : ") print (list(itertools.repeat(25, 4))) Output: