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

Cliff Wells cliff at develix.com
Sun Sep 14 21:51:19 CEST 2008


On Sun, 2008-09-14 at 19:28 +0100, Arnaud Delobelle wrote:
> On 14 Sep 2008, at 10:25, Cliff Wells wrote:
> 
> >> Now say you want to write that inline with a for-expression:
> >>
> >>     '-'.join(
> >> 	for J in I:
> >>             for j in J:
> >>                 YIELD j
> >> 	)
> >>
> >> That won't work because the j's will be accumulated in the inner loop
> >> and the outer loop won't accumulate anything, therefore returning an
> >> empty iterable.
> >
> > How about this way instead (since for-loop is now an expression):
> >
> > '-'.join(
> >    for j in ( for J in I: YIELD J ): YIELD j
> > )
> 
> After you've had a good night's sleep and when you look at this again,  
> you'll definitely think that you were too hasty in replying :)
> 

Ha!  I knew I should have gone to bed earlier =)

I = [ 'spam', 'eggs' ]

'-'.join ( 
     for J in I: YIELD ( for j in J: YIELD j ) 
)

Now if only I'd followed Guido's suggestion I'd actually be able to test
before I post ;-)

Cliff




More information about the Python-ideas mailing list