sync to Atlas repo

This commit is contained in:
Luciano Ramalho
2014-12-06 15:39:48 -02:00
parent b38e6fc5f2
commit dcd59eef31
12 changed files with 490 additions and 0 deletions

29
iterables/aritprog_v4.py Normal file
View File

@@ -0,0 +1,29 @@
"""
Arithmetic progression class
>>> ap = ArithmeticProgression(1, .5, 3)
>>> list(ap)
[1.0, 1.5, 2.0, 2.5]
"""
import array
from collections import abc
class ArithmeticProgression:
def __init__(self, begin, step, end=None):
self.begin = begin
self.step = step
self.end = end # None -> "infinite" series
def __iter__(self):
result = type(self.step)(self.begin)
forever = self.end is None
index = 0
while forever or result < self.end:
yield result
index += 1
result = self.begin + self.step * index
raise StopIteration