Йордан обнови решението на 03.04.2015 16:15 (преди над 9 години)
+def fibonacci():
+ a, b = 1, 1
+ while True:
+ yield a
+ a, b = b, a + b
+
+
+def primes():
+ a = 2
+ result = set()
+ while True:
+ for i in result:
+ if a % i == 0:
+ break
+ else:
+ result.add(a)
+ yield a
+ a += 1
+
+
+def alphabet(code=None, letters=None):
+ if letters is not None:
+ x = 0
+ while True:
+ if x >= len(letters):
+ break
+ else:
+ yield letters[x]
+ x += 1
+ elif code == 'lat':
+ i = 97
+ while True:
+ if i > 122:
+ break
+ else:
+ yield chr(i)
+ i += 1
+ elif code == 'bg':
+ j = 1072
+ while True:
+ if j > 1103:
+ break
+ elif j == 1099 or j == 1101:
+ j += 1
+ else:
+ yield chr(j)
+ j += 1
+
+
+def intertwined_sequences(iterable, generator_definitions=None):
+ global_dict = {}
+ fib = fibonacci()
+ prim = primes()
+ for hash_table in iterable:
+ i = ""
+ length = 0
+ cd = ""
+ lt = None
+ k = {}
+ for name, value in hash_table.items():
+ if name == "length":
+ length = value
+ elif name == "code":
+ cd = value
+ elif name == "letters":
+ lt = value
+ elif name == "sequence":
+ i = value
+ else:
+ k.update({name: value})
+ if i not in global_dict:
+ if i != 'fibonacci' and i != 'primes'and i != 'alphabet':
+ if k:
+ global_dict[i] = generator_definitions[i](**k)
+ else:
+ global_dict[i] = generator_definitions[i]()
+ alpha = alphabet(code=cd, letters=lt)
+ for j in range(length):
+ if i == 'fibonacci':
+ yield next(fib)
+ elif i == 'primes':
+ yield next(prim)
+ elif i == 'alphabet':
+ yield next(alpha)
+ else:
+ yield next(global_dict[i])