Людмил обнови решението на 31.03.2015 16:31 (преди над 9 години)
+import math
+import string
+from copy import copy
+from itertools import count, chain
+
+
+ALPHABETS = {
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя',
+ 'lat': string.ascii_lowercase}
+
+
+def fibonacci():
+ current, next = 1, 1
+ while True:
+ yield current
+ current, next = next, current + next
+
+
+def prime(number):
+ for divisor in range(2, int(math.sqrt(number)) + 1):
+ if number % divisor == 0:
+ return False
+ return True
+
+
+def primes():
+ return (number for number in chain([2], count(3, 2)) if prime(number))
+
+
+def alphabet(code=None, letters=None):
+ if letters:
+ for letter in letters:
+ yield letter
+ else:
+ for letter in ALPHABETS[code]:
+ yield letter
+
+
+GENERATORS = {'fibonacci': fibonacci, 'primes': primes, 'alphabet': alphabet}
+
+
+def intertwined_sequences(sequences, generator_definitions={}):
+ generator_definitions.update(GENERATORS)
+ used_generators = {}
+ for sequence in sequences:
+ sequence_name = sequence['sequence']
+ if sequence_name not in used_generators:
+ generator_args = copy(sequence)
+ del generator_args['sequence'], generator_args['length']
+ new_gen = generator_definitions[sequence_name](**generator_args)
+ used_generators[sequence_name] = new_gen
+ for _ in range(sequence['length']):
+ yield next(used_generators[sequence_name])