- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find replicated list by replicating each element n times

Suppose we have a list of n elements; we have to repeat each element in the list n number of times.

So, if the input is like nums = [1,5,8,3], then the output will be [1, 1, 1, 1, 5, 5, 5, 5, 8, 8, 8, 8, 3, 3, 3, 3]

To solve this, we will follow these steps −

- n := size of nums
- ret := a new list
- for each num in nums, do
- ret := ret concatenate a list with n number of nums

- return ret

## Example

Let us see the following implementation to get better understanding

def solve(nums): n = len(nums) ret = [] for num in nums: ret += [num]*n return ret nums = [1,5,8,3] print(solve(nums))

## Input

[1,5,8,3]

## Output

[1, 1, 1, 1, 5, 5, 5, 5, 8, 8, 8, 8, 3, 3, 3, 3]

- Related Articles
- Python Program to find the cube of each list element
- Program to find ith element by rotating k times to right
- Python Program to Find Element Occurring Odd Number of Times in a List
- Program to find modulus of a number by concatenating n times in Python
- How to create a replicated list of a list in R?
- Python program to right rotate a list by n
- How to extract first n values from each element in an R list?
- C++ program to find unique pairs such that each element is less than or equal to N
- Python program to rotate doubly linked list by N nodes
- Program to find sum of concatenated pairs of all each element in a list in Python?
- Python program to get the indices of each element of one list in another list
- Python program to Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple
- Python Program to assign each list element value equal to its magnitude order
- Python program to find N largest elements from a list
- Python Program to calculate n+nm+nmm.......+n(m times).

Advertisements