Created
March 8, 2017 01:21
-
-
Save ekozlowski/f4b839de89729fe7e678b2a90d3e14a7 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
# coroutine example | |
def look_for(pattern): | |
while True: | |
temp = yield | |
if pattern in temp: | |
print("I found {} in {}!".format(pattern, temp)) | |
else: | |
print("No {} in {}.".format(pattern, temp)) | |
if pattern == 'break': | |
break | |
if __name__ == "__main__": | |
c = look_for('ed') | |
c.send(None) # prime the "coroutine" | |
c.send('education') | |
c.send('fundamental') | |
c.send('ed was here!') | |
c.send('something else') | |
c.send('break') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment