Yielding a chain of values

Matt Hammond matt.hammond at rd.bbc.co.uk
Wed Aug 31 04:24:47 EDT 2005


> Well, maybe it's right both ways ;-) I.e., even though yield "is" now
> an expression, it is valid to use it as an expression-statement which
> evaluates the expression and discards the value. So I think you could
> still use the currently illegal "yield in" token sequence to mean that
> what follows is to be taken as an iterable whose full sequence is
> to be yielded sequentially as if
>
>     yield in iterable
>
> were sugar for
>
>     for _ in iterable: yield _

"yield in" could make sense when thought of as an expression too.

     x = yield in iterable

Would behave like a list comprehension. x would be assigned a list  
containing
the results of the successive yields. Equivalent to:

	x = [ yield r for r in iterable ]

regards


Matt
-- 

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.



More information about the Python-list mailing list