Status of PEP's?

Carel Fellinger cfelling at iae.nl
Thu Feb 28 17:29:35 CET 2002


Emile van Sebille <emile at fenx.com> wrote:
> "Remco Gerlich"
>> Compare:
>>
>> for i in 6: print i
>> for i in 6,7: print i
>> for i in 6,7,8: print i
>>
>> You wouldn't think the first line does something different, would you?

> Is that really any different from what we have now:

> for i in "Spam": print i

Yes, it clearly is!  `"Spam"' is a sequence, and iterating over a sequence
is understandable.

> for i in "Spam","and": print i

And here `"Spam", "and"' is a sequence of sequences, and again iterating
over a sequenc--even if it's a sequence of sequences--is understandable.

But iterating over an integer is even after that number theory lessons
we had last night still very hard for me to appreciate.


> I find the best argument for adding an iter method to ints is that it
> allows me to say:

>     for ii in iter(len(mylist)):

And how would this compare to

      for ii in indici(mylist):

This would read `for all ii in the indici for mylist', extremely clear
to me.  We could even consider enhancing range to accept a list in
case of a single argument.


> However, the clarity and intent conveyed by allowing this, particularly
> for newbies, more than offsets the gotcha's, which, once learned, is the
> same set of gotcha's in place for strings.

And here you lost me. How can turning a single number into a sequence of
all its preceding numbers be easy to understand for someone not versed
in modern number theory or without a crack for weird syntactic sugar.



-- 
groetjes, carel



More information about the Python-list mailing list