What's wrong with making this two lines?
In [1]: import random In [2]: xs = [10, 20, 30] In [3]: def foo(x): ...: return [x + i for i in range(3)] ...: ...: In [4]: def bar(y): ...: if random.random() < 0.3: ...: return None ...: return str(y) ...: ...: In [5]: ys = ((y, bar(y)) for x in xs for y in foo(x)) In [6]: {y: result for y, result in ys if result is not None} Out[6]: {10: '10', 11: '11', 20: '20', 21: '21', 22: '22', 30: '30', 32: '32'}
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/