Does anyone else use this little idiom?

James Matthews nytrokiss at gmail.com
Sun Feb 3 05:17:49 EST 2008


Because 0 is counted therefore i only have to do it 99 times

Thanks

On Feb 3, 2008 4:38 AM, Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:

> En Sun, 03 Feb 2008 01:03:43 -0200, James Matthews <nytrokiss at gmail.com>
> escribió:
>
> Sorry to be nitpicking, but people coming from other languages may get
> confused by the wrong examples:
>
> > What i do is a simple range call. for i in range(number of times i want
> > to repeat something)
> > I guess it comes from my C days for(i=0;i<100;i++) { or in python for i
> > in range(99):
>
> Should be `for i in range(100)` to match exactly the C loop. Both iterate
> 100 times, with i varying from 0 to 99 inclusive.
>
> >>  miller.paul.w at gmail.com wrote:
> >>
> >> > Ruby has a neat little convenience when writing loops where you don't
> >> > care about the loop index: you just do n.times do { ... some
> >> > code ... } where n is an integer representing how many times you want
> >> > to execute "some code."
> >> >
> >> > In Python, the direct translation of this is a for loop.  When the
> >> > index doesn't matter to me, I tend to write it as:
> >> >
> >> > for _ in xrange (1,n):
> >> >    some code
>
> Should be `for _ in xrange(n)` to match the Ruby example. Both iterate n
> times.
>
> > On Feb 3, 2008 3:34 AM, Roy Smith <roy at panix.com> wrote:
> >
> >> But, more to the point, I'd try to find variable name which described
> >> why I was looping, even if I didn't actually use the value in theloop
> >> body:
>
> Me too. Government don't collect taxes by the number of variable names
> used (yet).
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://search.goldwatches.com/?Search=Movado+Watches
http://www.jewelerslounge.com
http://www.goldwatches.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080203/4f9908e8/attachment-0001.html>


More information about the Python-list mailing list