Skip to content

Instantly share code, notes, and snippets.

@hongqn
Last active January 2, 2016 11:19
Show Gist options
  • Save hongqn/8295839 to your computer and use it in GitHub Desktop.
Save hongqn/8295839 to your computer and use it in GitHub Desktop.
genOdd := func() chan int {
ch := make(chan int)
go func() {
i := 1
for {
ch <- i
i += 2
}
}()
return ch
}
for i := range genOdd() {
fmt.Println(i)
}
def gen_odd():
i = 1
while True:
yield i
i += 2
for i in gen_odd():
print i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment