Moldytzu
Moldytzu

Reputation: 25

Is there any way to make two steps in a one step for loop?

I am using Python 3.8 and I was wandering if is there any way to make two steps in a one step for loop like this:

for i in range(15):
 if i == 2:
  # make two steps
 else:
  #continue normaly

Upvotes: 1

Views: 186

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191738

Manipulate the generator manually

gen = iter(range(15)) 
while True:
    try:
        i = next(gen) 
        if i ==2:
            next(gen) 
            continue 
        else:
            pass
    except: StopIteration
        break 

Upvotes: 1

Related Questions