Countdown

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Mon Jun 26 04:02:58 EDT 2000


Will Ware wrote in comp.lang.python:
> Remco Gerlich (scarblac-spamtrap at pino.selwerd.nl) wrote:
> > for i in range(len(thing)):
> >    print thing[-i]
> 
> If thing = [1, 2, 3, 4, 5], then this piece of code will print
> 1, 5, 4, 3, 2. The code below has probably the less surprising
> effect of printing 5, 4, 3, 2, 1.
> 
> for i in range(len(thing)):
>     print thing[-i-1]

Sigh. All my posts have small errors recently. Here I'm trusting the
behavior of indexing in Python too much (it avoids off by one errors,
right?...)

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl
  Murphy's Rules, "A family way":
   Population increases by 5 per cent each week in Universe III (Central
   Texas Computing)... This is possible only if every female is
   constantly pregnant with dodectuplets (a litter of 12).



More information about the Python-list mailing list