range(seq)?

Magnus Lie Hetland mlh at vier.idi.ntnu.no
Fri Feb 8 07:05:37 EST 2002


I just had an idea... I'm sure there are others out there who don't
particularly like the much-used (and necessary) expression
range(len(seq))... One proposed solution is to make integers iterable,
so one can do:

  for x in len(seq): ...

That is one way of doing it, of course (i'm not sure I'm all that fond
of it, but that's another matter ;)

Then it occurred to me that perhaps it could be done the _other_ way:

  for x in range(seq): ...

I.e. let range() take a sequence (or iterable) as an argument, and
generate range(len(seq)). (I guess in mathematical terms, if one sees
a sequence as a function, that domain(seq) would be more appropriate,
but what the hey ;)

Of course, we have the proposed indices(seq)... But by allowing
range() to work on iterables, we wouldn't have to add another
function. And I can't see any significant code breakages (but I'm sure
there are some... :)

So, why is this a stupid idea? (I'm sure it is...)

--
Magnus Lie Hetland                                  The Anygui Project
http://hetland.org                                  http://anygui.org



More information about the Python-list mailing list