Matthew Fitzgibbons wrote:
[EMAIL PROTECTED] wrote:


reHist = [0, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
count = 0
for i, d in enumerate(reHist):
    if d == 0:
        count = 0
    else:
        count += 1
    if count == 5:
        break
else:
    raise Exception("No data found")
reHist = reHist[i-4:]
print reHist

This is what I would have suggested, except that the 'if count' test should be left under the else clause, as in the original, so I consider it the best of the responses ;-)

I thought of the repeated slicing alternative, but it would be slightly slower. However, for occasional runs, the difference would be trivial.

Worrying about what Psyco does for this problem is rather premature optimization.

My quarter's worth....

tjr


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to