Why I think range is a wart
Russell E. Owen
owen at xastrox.xwashingtonx.edu.invalid
Thu Mar 14 12:13:16 EST 2002
In article <ltsu8us0qdsj6r8oersrac465589ot644c at 4ax.com>,
Gonçalo Rodrigues <op73418 at mail.telepac.pt> wrote:
>For starters, range (and xrange) is a perfectly sensible, reasonable and
>useful buit-in. But the biggest use I make of it is in iterating through
>a list, e.g. as in
>
>for index in range(len(mylist)):
> <whatever>
>
>and in the <whatever> body I need to make use of the indexes. I am not
>sufficiently qualified to say if this is Pythonic or not, but I find
>myself doing this quite often.
I agree. In particular, I often find myself wanting to deal with items
from multiple lists of equal length. Often map or zip would do the job
(though at the cost of creating a new list for which I have no use!) but
a cleaner way to express it would be appreciated, something like:
for item1, item2 in list1, list2
# lots of code here
Regarding the suggestion to add the dictionary iterators methods to
lists: nice idea. The analogy is nice. If any such methods are added,
I'd vote for adding the full suite (iterkeys, itervalues, iteritems...),
for consistency. I doesn't completely solve the problem I'm facing, but
would clean up the notation a little and it makes plenty of sense.
-- Russell
--
Return owen
address astro
garbled washington
in header edu
More information about the Python-list
mailing list