Error in loop with python -


i have list lst = [1, 2, 3, 4, 5, 6, 3, 5, 3] , every iteration, elem == 3 want print strings before that, while elem not 3 again. want

2 3: 0 1 1 2 6 3: 3 4 4 5 5 6 8 3: 7 5 

but don't know, how go previous string

for i, el in enumerate(lst):     if lst[i] == 3:         print i, el         -= 1 

but it's inly elem-1

something this?

    lst = [1, 2, 3, 4, 5, 6, 3, 5, 3]     previous = []      i, el in enumerate(lst):         if lst[i] == 3:             print i, el,":"             p in previous:                 print p[0] , p[1]             previous = []         else:             previous.append((i,el)) 

Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -