Илиан обнови решението на 03.04.2015 16:59 (преди над 9 години)
+import string
+from itertools import islice
+
+
+class fibonacci():
+ def __init__(self):
+ self.current = 1
+ self.previous = 0
+
+ def __iter__(self):
+ self.current = 1
+ self.previous = 0
+ return self
+
+ def __next__(self):
+ return_index = self.current
+ self.current, self.previous = self.previous + self.current, return_index
+ return return_index
+
+
+class primes():
+ def primality_check(self, number):
+ for i in range(2,number):
+ if number % i == 0:
+ return False
+ return True
+
+ def __init__(self):
+ self.current = 2
+
+ def __iter__(self):
+ self.current = 2
+ return self
+
+ def __next__(self):
+ while (not self.primality_check(self.current)):
+ self.current = self.current + 1
+ result, self.current = self.current, self.current + 1
+ return result
+
+class alphabet():
+ def __init__(self, code, letters=''):
+ self.current = 0
+ if letters != '':
+ self.letters = letters
+ elif code == 'bg':
+ self.letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ elif code == 'lat':
+ self.letters = string.ascii_lowercase
+
+ def __iter__(self):
+ self.__init__('lat')
+ return self
+
+ def __next__(self):
+ result, self.current = self.current, self.current + 1
+ return self.letters[result]