I have the following loop in Python that I want to turn into a list comprehension:
index = 0
for i in range(number):
vec[i] = index
if condition:
index += 1
This should make vec look something like [0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 5, 6, 6, 6]. However, I am struggling to create a list comprehension for this.
My attempts look like this:
y=[]
index = 0
[index+=1 and y.append(index) if condition else y.append(index) for _ in range(number)]
In iPython this just doesn't even execute.