Here’s something I was trying to do in ICE (without using any Repeats).

Given an array like

a = [ 5, 2 ,3 ]

create an array like

b = [ 0, 0, 0, 0, 0, 1, 1, 2, 2, 2 ]

See the pattern? (a[0] is 5, so array b has five elements with value 0).

In Python, using list comprehension, you can do it like this:

a = [ 5, 2, 3 ]
print [ i for i in range( len(a) ) for j in range( a[i] )]

The list comprehension is the equivalent of:

for i in range( len(a) ):
for j in range( a[i] ):
print i

### Like this:

Like Loading...

*Related*