Created
June 22, 2011 09:42
-
-
Save bpgergo/1039774 to your computer and use it in GitHub Desktop.
Ngrams with coroutines 2
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 | |
def filter_chars(accepted_chars,target): | |
""" A coroutine to filter out unaccepted chars. | |
Accepts one char at a time """ | |
while True: | |
c = (yield) | |
if c.lower() in accepted_chars: | |
target.send(c.lower()) | |
@coroutine | |
def counter(matrix): | |
""" A counter sink """ | |
while True: | |
a, b = (yield) | |
matrix[pos[a]][pos[b]] += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment