Created
January 23, 2017 18:00
-
-
Save jrjames83/4a2ad36ab3b598d1ce1a7962b0a89bac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Multiple yield statements | |
| def gen_up_to(limit): | |
| n = 0 | |
| while n <= limit: | |
| if n % 2 <= 0: | |
| yield (n, "even") | |
| if n % 2 > 0: | |
| yield (n, "odd") | |
| n += 1 | |
| yield 'All Done' | |
| it = gen_up_to(10) | |
| for val in it: | |
| print (it.__next__()) | |
| """ Where are the even ones? | |
| (1, 'odd') | |
| (3, 'odd') | |
| (5, 'odd') | |
| (7, 'odd') | |
| (9, 'odd') | |
| All Done | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment