Python: Best way to frame a loop with 2 alternating tasks -


i have list of items need process. easy enough: simple for x in list.

however, commands inside loop need different, on alternating basis.
n = 0 handled 1 way, n = 1 different way; n = 2 same n = 0. note n , x different!

at moment, way can think of doing incremental counter , if statements. i'm presuming there's easier way?

hope makes sense. thanks

you use enumerate , modulo alternate:

li = ['a', 'b', 'c'] idx, ch in enumerate(li):     if idx % 2 == 0:         #     else:         # b 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -