xrange

Bryan belred1 at yahoo.com
Mon Jun 23 02:07:47 EDT 2003


"Raymond Hettinger" <vze4rx4y at verizon.net> wrote in message
news:PmwJa.6109$N%6.5701 at nwrdny02.gnilink.net...
> "Bryan" <belred1 at yahoo.com> wrote in message
> news:KKsJa.107828$YZ2.275985 at rwcrnsc53...
> > oh no...
> >
> > >>> for i in enumerate(['a', 'b', 'c']): print i
> > ...
> > (0, 'a')
> > (1, 'b')
> > (2, 'c')
> > >>> for i in zip(count(), ['a', 'b', 'c']): print i
> > ...
> > (0, 'a')
> > (1, 'b')
> > (2, 'c')
> > >>> for i in izip(count(), ['a', 'b', 'c']): print i
> > ...
> > (0, 'a')
> > (1, 'b')
> > (2, 'c')
>
>
>
> Oh please!  That's just silly.
>
> >>> print 1
> 1
> >>> print range(2)[1]
> 1
> >>> print 22-21
> 1
> >>> print str("1")
> 1
>
> Of course, general purpose constructs can be made to emulate one
> another (for instance, most looping constructs reduce to "if" and "goto").
>

well, i think i was only half taunting, but i don't think it's silly at
all... i do think that a newbie trying to figure out what to do is going to
have a somewhat tougher time.   in my three examples, there are only subtle
differences.  i myself would probably use the enumerate one, but after
reading the itertools documentation, i found the izip one first.  after i
saw enumerate, it wasn't immediately obvious to me what others would do.
izip has the look and feel of the classic zip.  i knew others would easily
be able to read it.  enumerate hides the the count() appears simpilar, but
because of hiding the count(), it isn't as obvious.  i only brought this up
because in my own personal python experience, i have never encounted this
feeling of "not knowing how others would do it".  i wasn't trying to zen-ize
this to death.  maybe the documentation should help guide the user about the
issues of backwards compatibily, when to use the classic zip/map etc, and
when to use the new ones,  and when to blend the two styles as i did with
the zip example.  also, i think the itertools documentation should have a
reference to enumerate even though it's a builtin,  and visa-vera.


bryan







More information about the Python-list mailing list