Константин обнови решението на 03.04.2015 09:23 (преди над 9 години)
+# -*- coding: utf-8 -*-
+def fibonacci():
+ a, b = 1, 1
+ while True:
+ yield a
+ a, b = b, a + b
+
+
+def primes():
+ n = 2
+ primes = []
+ while True:
+ is_prime = True
+ for p in primes:
+ if n % p == 0:
+ is_prime = False
+ break
+
+ if is_prime:
+ primes.append(n)
+ yield n
+
+ n += 1
+
+
+DEFAULT_ALPHABETS = {
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя',
+ 'lat': 'abcdefghijklmnopqrstuvwxyz',
+}
+
+
+def alphabet(code='', letters=''):
+ used_alphabet = letters if letters else DEFAULT_ALPHABETS.get(code)
+ current_index = 0
+ while True:
+ yield used_alphabet[current_index]
+ current_index += 1
+
+
+def intertwined_sequences(func_calls):
+ result = []
+ called_functions = {}
+ for call in func_calls:
+ if 'sequence' not in called_functions:
+ sequence = globals()[call['sequence']]
+
+ if call['sequence'] is 'alphabet':
+ kwargs = {
+ 'code': call.get('code', ''),
+ 'letters': call.get('letters', ''),
+ }
+
+ method = sequence(**kwargs)
+ else:
+ method = sequence()
+
+ called_functions[call['sequence']] = method
+
+ for call in func_calls:
+ for i in range(call['length']):
+ result.append(next(called_functions[call['sequence']]))
+
+ return result