Skip to content
Advertisement

Tag: fibonacci

How to write a generator class?

I see lot of examples of generator functions, but I want to know how to write generators for classes. Lets say, I wanted to write Fibonacci series as a class. Output: Why is the value self.a not getting printed? Also, how do I write unittest for generators? Answer How to write a generator class? You’re almost there, writing an Iterator

Efficient calculation of Fibonacci series

I’m working on a Project Euler problem: the one about the sum of the even Fibonacci numbers. My code: The problem’s solution can be easily found by printing sum(list2). However, it is taking a lot of time to come up with the list2 I’m guessing. Is there any way to make this faster? Or is it okay even this way…

Advertisement