Емил обнови решението на 31.03.2015 21:43 (преди над 9 години)
+from math import sqrt
+
+
+BG_LETTERS = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+LATIN_LETTERS = 'abcdefghijklmnopqrstuvwxyz'
+
+
+def fibonacci():
+ a, b = 1, 1
+ while True:
+ yield a
+ a, b = b, a + b
+
+
+def is_prime(number):
+ for i in range(2, (int(sqrt(number) + 1))):
+ if number % i == 0:
+ return False
+ return True
+
+
+def primes():
+ number = 2
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def alphabet_helper(letters):
+ for char in letters:
+ yield char
+
+
+def alphabet(code, letters=''):
+ if code == 'bg' and not letters:
+ yield from alphabet_helper(BG_LETTERS)
+ elif code == 'lat' and not letters:
+ yield from alphabet_helper(LATIN_LETTERS)
+ else:
+ letters = code
+ yield from alphabet_helper(letters)
+
+
+"""Не е в началото, защото трябва да е след дефинициите на генераторите"""
+PRIMARY_DEFINITIONS = {'fibonacci': fibonacci,
+ 'primes': primes,
+ 'alphabet': alphabet}
+
+
+def intertwined_sequences(iterable, generator_definitions={}):
+ generator_definitions = dict(generator_definitions)
+ generator_definitions.update(PRIMARY_DEFINITIONS)
+ definitions = {}
+ for item in iterable:
+ name = item['sequence']
+ if name not in definitions:
+ arguments = {k: v for k, v in item.items()
+ if k != 'sequence' and k != 'length'}
+ current_generator = iter(generator_definitions[name](**arguments))
+ definitions[name] = current_generator
+ for i in range(item['length']):
+ yield next(definitions[name])
code
не е задължителен аргумент на alphabet
.