Re: [Prothon-user] RE: Re: [Prothon-commits] rev 232 - trunk/src

"Mark Hahn" <[email protected]> Wed, 31 Mar 2004 15:15:11 -0800
Newsgroups gmane.comp.lang.prothon.devel
Message-ID <005001c41776$05501290$d701a8c0@MarkVaio>
Ben: I was wrong.  Your first implementation was correct.  Just  make the
generator return keys.

dict.items() should be a generator returning tuples of key,value pairs.

I have an idea for making everything that normally returns a list in Python
return a generator in Prothon but have all generators respond to list
functions.  I'll post a new msg about this.

Magnus Lycka wrote:
> Mark Hahn wrote:
>> hmmm, does "for key, value in dict:" work correctly now?
>
> You're breaking Python compatibility if you want that to
> work. "for key, value in dict:" only works if the key is
> a tuple with two elements, and that's hardly what you want.
>
> Loop over a dict is the same as looping over dict.keys(),
> except that it uses an iterator instead of building a list.
>
>>>> d = {1:2,3:4}
>>>> d
> {1: 2, 3: 4}
>>>> for k,v in d:
> print k,v
>
> TypeError: unpack non-sequence
>>>> d = {(1,1):2,(3,3):4}
>>>> for k,v in d:
> print k,v
>
> 1 1
> 3 3