Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Hey, can someone explain to me what a python generator is and how to use it?I need to know it to solve a problem.Thanks
 one year ago
 one year ago
Hey, can someone explain to me what a python generator is and how to use it?I need to know it to solve a problem.Thanks
 one year ago
 one year ago

This Question is Open

moli1993Best ResponseYou've already chosen the best response.0
refer http://wiki.python.org/moin/Generators
 one year ago

bwCABest ResponseYou've already chosen the best response.0
http://docs.python.org/2.7/howto/functional.html#generators http://docs.python.org/2.7/reference/simple_stmts.html#theyieldstatement http://docs.python.org/2.7/library/stdtypes.html#generatortypes http://docs.python.org/2.7/reference/expressions.html#yieldexpressions http://docs.python.org/2.7/howto/functional.html#generatorexpressionsandlistcomprehensions
 one year ago

msmithhnovaBest ResponseYou've already chosen the best response.0
Here's a fibonacci generator. def fib(n): a,b = 0,1 for _ in xrange(n): yield b a,b = b, a+b And a test print fib(10) print list(fib(10)) for i in fib(10): print i, And the output <generator object fib at 0x0298F490> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] 1 1 2 3 5 8 13 21 34 55
 one year ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.