Created
January 9, 2024 14:44
-
-
Save srusskih/f6d7d1f60edfc5a63dada48fa59ecac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: collector = {} | |
In [2]: def _generator(collector): | |
...: for i in range(10): | |
...: collector.add(i*2) | |
...: yield i | |
...: | |
In [3]: collector = set() | |
In [4]: gen = _generator(collector) | |
In [5]: list(gen) | |
Out[5]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
In [6]: collector | |
Out[6]: {0, 2, 4, 6, 8, 10, 12, 14, 16, 18} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment