We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
To repeat each element in a list a given number of times, use a simple list comprehension like: return [x for x in arr for _ in range(num)]. It preserves the order and repeats each item num times. Learn more cool comparisons like this in the Doraemon X APK mod vs official comparison.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
List Replication
You are viewing a single comment's thread. Return to all comments →
To repeat each element in a list a given number of times, use a simple list comprehension like:
return [x for x in arr for _ in range(num)]
. It preserves the order and repeats each itemnum
times. Learn more cool comparisons like this in the Doraemon X APK mod vs official comparison.