Aнтония обнови решението на 03.04.2015 00:08 (преди над 9 години)
+import itertools
+import inspect
+
+ALPHABETS = {'lat': 'abcdefghijklmnopqrstuvwxyz',
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'}
+
+
+def fibonacci():
+ first, second = 1, 1
+ yield first
+ yield second
+ while True:
+ first, second = second, first + second
+ yield second
+
+
+def primes():
+ number = 2
+ while True:
+ if all([number % divisor for divisor in range(2, number)]):
+ yield number
+ number += 1
+
+
+def alphabet(**kwargs):
+ if kwargs.get('letters'):
+ return iter(kwargs.get('letters'))
+ if kwargs.get('code'):
+ return iter(ALPHABETS[kwargs.get('code')])
+
+
+def intertwined_sequences(sequence_objects, generator_definitions=None):
+ functions = {'fibonacci': fibonacci(),
+ 'primes': primes(),
+ 'alphabet': alphabet(code='bg')}
+
+ if generator_definitions:
+ for key, values in generator_definitions.items():
+ func_args = find_function_argument(sequence_objects, values)
+ if func_args:
+ functions[key] = iter(values(func_args))
+ else:
+ functions[key] = iter(values())
+
+ for objects in sequence_objects:
+ for i in range(objects.get('length')):
+ yield next(functions[objects['sequence']])
+
+
+def find_function_argument(sequence_objects, function):
+ function_argument = inspect.getargspec(function)[0]
+ if function_argument:
+ for seq in sequence_objects:
+ if function_argument[0] in seq:
+ return seq[function_argument[0]]