Message222811
Will playing with generators and `yield from` I found some inconsistency.
list comprehension with yield(-from) would return a generator.
generator comprehension would yield some None in the middle of the expected values.
Examples:
l = ["abc", range(3)]
g1 = [(yield from i) for i in l]
print(g)
<generator object <listcomp> at 0x7f5ebd58b690>
print(list(g))
['a', 'b', 'c', 0, 1, 2] # this result is super cool !
g2 = ((yield from i) for i in l)
print(g2)
<generator object <genexpr> at 0x7f5ebd58b6e0>
print(list(g2))
['a', 'b', 'c', None, 0, 1, 2, None]
For `g1`: it returns a generator because the listcomp contains a `yield from`.
For `g2` it append None because it yield the return value of `yield from i`.
It could be rewritten as:
def comp(x):
for i in x:
yield (yield from i) |
|
Date |
User |
Action |
Args |
2014-07-11 23:06:27 | hakril | set | recipients:
+ hakril |
2014-07-11 23:06:27 | hakril | set | messageid: <1405119987.38.0.925003339613.issue21964@psf.upfronthosting.co.za> |
2014-07-11 23:06:27 | hakril | link | issue21964 messages |
2014-07-11 23:06:27 | hakril | create | |
|