Станислав обнови решението на 31.03.2015 21:34 (преди над 9 години)
+import itertools
+
+
+ALPHABETS = {
+ 'lat': 'abcdefghijklmnopqrstuvwxyz',
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщюя'
+}
+
+
+def fibonacci():
+ first, second = 1, 1
+ while True:
+ yield first
+ first, second = second, first+second
+
+
+def is_prime(num):
+ return num > 1 and all(num % divisor for divisor in range(2, num))
+
+
+def primes():
+ return (num for num in itertools.count() if is_prime(num))
+
+
+def alphabet(code=None, letters=None):
+ return (letter for letter in (letters or ALPHABETS[code]))
+
+
+GENERATORS = {
+ 'fibonacci': fibonacci,
+ 'primes': primes,
+ 'alphabet': alphabet
+}
+
+
+def intertwined_sequences(generator_descriptions, generator_definitions={}):
+ generators = dict(GENERATORS, **generator_definitions)
+ generators_cache = {}
+ for description in generator_descriptions:
+ sequence = description.pop('sequence')
+ length = description.pop('length')
+ if sequence not in generators_cache:
+ generators_cache[sequence] = iter(
+ generators[sequence](**description))
+
+ for _ in range(length):
+ yield next(generators_cache[sequence])
ъь? :)
Аз съм неграмотен.