Цвета обнови решението на 01.04.2015 01:17 (преди над 9 години)
+import itertools
+
+
+def fibonacci():
+ a, b = 0, 0
+ if a == 0:
+ a += 1
+ while True:
+ b += a
+ a = b - a
+ yield b
+
+
+def primes():
+ def is_prime(n):
+ if n < 2:
+ return False
+ return bool(not (len([i for i in range(2, n // 2 + 1) if n % i == 0])))
+ return (i for i in itertools.count(2) if is_prime(i))
+
+
+def alphabet(**kwargs):
+ if 'letters' in kwargs:
+ return (ch for ch in kwargs['letters'])
+ else:
+ if kwargs['code'] == 'lat':
+ return (ch for ch in 'abcdefghijklmnopqrstuvwhyz')
+ else:
+ return (ch for ch in 'абвгдежзийклмнопрстуфхцчщщъьюя')
+
+
+def intertwined_sequences(generators, **kwargs):
+ iters = {}
+
+ for g in generators:
+ if g['sequence'] not in ['primes', 'fibonacci', 'alphabet']:
+ attributes = {key: g[key]
+ for key in g if key != 'sequence' and key != 'length'}
+ iters[g['sequence']] = iter(
+ kwargs['generator_definitions'][g['sequence']](
+ **attributes))
+ else:
+ if not g['sequence'] in iters:
+ if g['sequence'] != 'alphabet':
+ iters[g['sequence']] = iter(globals()[g['sequence']]())
+ else:
+ if 'code' in g:
+ iters[g['sequence']] = iter(
+ globals()[g['sequence']](code=g['code']))
+ else:
+ iters[g['sequence']] = iter(
+ globals()[g['sequence']](letters=g['letters']))
+
+ for _ in range(g['length']):
+ yield next(iters[g['sequence']])
Нужда от рефакториране