[Python-Dev] re: Sets BOF / for in dict

Guido van Rossum guido@digicool.com
Sun, 04 Feb 2001 11:55:08 -0500


> I've spoken with Barbara Fuller (IPC9 org.); the two openings for a
> BOF on sets are breakfast or lunch on Wednesday the 7th.  I'd prefer
> breakfast (less chance of me missing my flight :-); is there anyone
> who's interested in attending who *can't* make that time, but *could*
> make lunch?

Fine with me.

> And meanwhile:
> 
> > Ka-Ping Yee:
> >     - the key:value syntax suggested by Guido (i like it quite a lot)
> 
> Greg Wilson:
> Did another quick poll; feeling here is that if
> 
>     for key:value in dict:
> 
> works, then:
> 
>     for index:value in sequence:
> 
> would also be expected to work.  If the keys to the dictionary are (for
> example) 2-element tuples, then:
> 
>     for (left, right):value in dict:
> 
> would also be expected to work, just as:
> 
>     for ((left, right), value) in dict.items():
> 
> now works.

Yes, that's all non-controversial.

> Question: would the current proposal allow NumPy arrays (just as an
> example) to support both:
> 
>     for index:value in numPyArray:
> 
> where 'index' would get tuples like '(0, 3, 2)' for a 3D array, *and*
> 
>     for (i, j, k):value in numPyArray:
> 
> If so, then yeah, it would tidy up a fair bit of my code...

That's up to the numPy array!  Assuming that we introduce this
together with iterators, the default NumPy iterator could be made to
iterate over all three index sets simultaneously; there could be other
iterators to iterate over a selection of index sets (e.g. to iterate
over the rows).  However the iterator can't be told what form the
index has.

--Guido van Rossum (home page: http://www.python.org/~guido/)