Skip to content

Instantly share code, notes, and snippets.

@ekozlowski
Created March 8, 2017 01:21
Show Gist options
  • Save ekozlowski/f4b839de89729fe7e678b2a90d3e14a7 to your computer and use it in GitHub Desktop.
Save ekozlowski/f4b839de89729fe7e678b2a90d3e14a7 to your computer and use it in GitHub Desktop.
# 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