Диана обнови решението на 29.03.2015 23:03 (преди над 9 години)
+# encoding: utf-8
+from itertools import count
+
+
+def fibonacci():
+ first, second = 1, 1
+ while True:
+ yield first
+ first, second = second, first + second
+
+
+def is_prime(dividend):
+ if dividend < 2:
+ return False
+ if dividend == 2:
+ return True
+ for divisor in range(2, int(dividend ** 1 / 2) + 1):
+ if dividend % divisor == 0:
+ return False
+ return True
+
+
+def primes():
+ return (number for number in count(1) if is_prime(number))
+
+
+def alphabet(code=None, letters=None):
+ if code == 'lat':
+ alphabet = 'abcdefghigklmnopqrstuvwxyz'
+ else:
+ alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ if letters:
+ alphabet = letters
+ for letter in alphabet:
+ yield letter
+
+
+def intertwined_sequences(generators, generator_definitions):
+ generator_definitions.update({'fibonacci': fibonacci,
+ 'primes': primes,
+ 'alphabet': alphabet})
+ iterators = {}
+ for generator in generators:
+ arguments = {key: value for key, value in generator.items()
+ if key not in ('sequence', 'length')}
+ if generator['sequence'] not in iterators:
+ iter = generator_definitions[generator['sequence']](**arguments)
+ iterators[generator['sequence']] = iter
+ for _ in range(generator['length']):
+ yield next(iterators[generator['sequence']])