Why I think range is a wart.

Martijn Faassen m.faassen at vet.uu.nl
Thu Mar 14 18:12:36 EST 2002


John Roth <johnroth at ameritech.net> wrote:
> It happens to me too, mostly when I'm using a sliding window
> type algorithm, that is, I need to look at two adjacent members
> of the list. You can't do this easily by iterating through the list;
> unrolling the first entry and the last entry are a pain.

> Is there a way of handling this nicely? Somehow I doubt it.

I occasionally use this:

  last_element = list[0]
  for element in list[1:]:
     # some_operation on element and last_element here
     last_element = element

Do you mean that by unrolling the first and last entries? I mean, there's
not much unrolling going on here.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list