>>> [i for i in range(3) for _ in range(2)]
[0, 0, 1, 1, 2, 2]
5
votes
a general solution;
m = 3 #the list of integers
n = 2 # of repetitions
[x for x in range(m) for y in range(n)]
2
votes
>>> [int(x/2) for x in range(6)]
[0, 0, 1, 1, 2, 2]
1
votes
My solution:
def explode_list(p,n):
arr=[]
track=0
if n==0:
return arr
while track<len(p):
m=1
while m<=n:
arr.append(p[track])
m=m+1
track=track+1
return arr
0
votes
You might get away with this:
[floor(x/2) for x in range(6)]
edit1
[int(x/2) for x in range(6)]
is the more portable solution in the same vein. Although the other presented answers seem better.
0
votes
[x/2 for x in range(6)]
update:
[x//2 for x in range(6)] #ok now ?
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more