python - get specific index when using izip over list -


i want iterate on list , find latest "consecutive value".

what mean, well:

if have list pricevalue = [423, 399, 390, 400, 430, 420, 423], latest consecutive value 2 last indexes: 420 423, index number: 5 , 6.

i want iterate , index @ right place

at moment use:

for x, y in itertools.izip(pricevalue, pricevalue[1:]):      print x, y     if y > x:         #print x, y         print pricevalue.index(y), pricevalue.index(x) 

but problem print index "0" , "5" since value 423 found @ index 0.

how right index?

note: can't tag "izip" in tags.

use enumerate yields index original items:

>>> i, x in enumerate(['a', 'b', 'c']): ...     print i, x  # i: index, x: item ... 0 1 b 2 c 

>>> import itertools >>> >>> xs = [423, 399, 390, 400, 430, 420, 423] >>> [i i, (x, y) in enumerate(itertools.izip(xs, xs[1:])) if y > x] [2, 3, 5] >>> [(i, i+1) i, (x, y) in enumerate(itertools.izip(xs, xs[1:])) if y > x] [(2, 3), (3, 4), (5, 6)] 

for i, (x, y) in enumerate(itertools.izip(xs, xs[1:])):     if y > x:         print i, + 1, x, y  # prints # 2 3 390 400 # 3 4 400 430 # 5 6 420 423 

Comments