Теодор обнови решението на 30.03.2015 01:10 (преди над 9 години)
+from math import floor, sqrt
+
+
+def fibonacci():
+ a, b = 0, 1
+ yield b
+ while True:
+ a, b = b, a + b
+ yield b
+
+
+def primes():
+ n = 2
+ yield n
+ while True:
+ n += 1
+ for i in range(2, floor(sqrt(n)) + 1):
+ if n % i == 0:
+ break
+ else:
+ yield n
+
+
+def alphabet(code=None, letters=None):
+ built_in = {'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя',
+ 'lat': 'abcdefghijklmnopqrstuvwxyz'}
+ if not letters:
+ letters = built_in[code]
+ return (letter for letter in letters)
+
+
+def intertwined_sequences(sequences, generator_definitions={}):
+ existing_generators = {}
+ generator_definitions.update(globals())
+ fixed_keys = ('sequence', 'length')
+
+ for sequence in sequences:
+ name = sequence['sequence']
+ if name in existing_generators:
+ generator = existing_generators[name]
+ else:
+ args = {i: sequence[i] for i in sequence if i not in fixed_keys}
+ generator = generator_definitions[name](**args)
+ existing_generators[name] = generator
+ for _ in range(sequence['length']):
+ yield next(generator)