Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Wayoutfinisher

  • 3 years 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

  • This Question is Open
  1. moli1993
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    refer http://wiki.python.org/moin/Generators

  2. msmithhnova
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 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

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy