range(seq)?

Magnus Lie Hetland mlh at vier.idi.ntnu.no
Sat Feb 9 04:55:57 EST 2002


In article <mailman.1013206876.19221.python-list at python.org>,
James_Althoff at i2.com wrote:
>
>[Magnus Lie Hetland]
>>   for x in range(seq): ...
>>
>> I.e. let range() take a sequence (or iterable) as an argument, and
>> generate range(len(seq)).
>
>[Jeff Shannon]
>>This seems more logical and intuitive to me, than the previous
>>suggestions.
>
>What Jython users will appreciate is that the above suggestion --
>although it might be handy for Pythonic structures and, possibly,
>might be "more logical and intuitive" than other suggestions --
>doesn't necessarily help with the world of structures one encounters
>outside the arena of 100% Python.

That depends on how well-behaved the container objects are (i.e.
implementing __len__).

> Java/Swing tables, for example, cannot be passed to the Python len
>() function (they are two-dimensional, for starters, and are not defined as
>a sequence of sequences).

OK. But these won't work with the normal "for x in container" either,
right? It seems that when dealing with this sort of object one would
either have to write a wrapper (e.g. for use with adapt()) or accept
that they don't present a Pythonic interface for iteration, e.g. by
using the plain old "for i in range(table.getRowCount())". Sounds
quite fair to me.

> So such an extension to the range() function
>won't make it any easier to deal with (certain) Java structures in Jython.

That's quite true.

>PEP 276, for example, suggests a simple way to deal with index-based
>structures that have been designed outside the sphere of Python practices
>while also making it easier at times to deal with Pythonic designs.

Maybe. I'm not full -1 on PEP 276 myself, but I don find the concept a
bit odd... That one can iterate over a number; Hm...

>
>Jim
>

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



More information about the Python-list mailing list