[Python-ideas] Statements vs Expressions... why?

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Sep 16 03:06:02 CEST 2008

Cliff Wells wrote:

> s = 'abc'
> x = for c in s: YIELD c     # x = 'a', 'b', 'c'

You mean that the value of (for c in s: YIELD c) is
a tuple? Or that it's an iterator that produces that
series of values?

> I = [ 'spam', 'eggs' ]
> for J in I:                 # J = 'spam' then 'eggs'
>     YIELD (                 # evaluate to an iterable
>         for j in J: YIELD j # j is 's' then 'p' then ...
>     )
 > so we get '-'.join( 's','p','a','m','e','g','g','s' )

I'm still not getting a clear idea of what semantics
you intend for a for-loop-with-YIELD. Neither of the
interpretations I suggested above (sequence or iterator)
seems to produce this result.

> maybe this is clearer as
> for J in I: 
>     tmp = for j in J: YIELD j
>     YIELD tmp

No, that's not any clearer. Can you provide a translation
into current, valid Python?


More information about the Python-ideas mailing list