Галин обнови решението на 03.04.2015 16:32 (преди над 9 години)
+def fibonacci():
+ fib = 1
+ fib1 = 1
+ while True:
+ yield fib
+ fib, fib1 = fib1, fib + fib1
+
+
+def is_prime(a):
+ if a == 1:
+ return False
+ for i in (range(2, a)):
+ if a % i == 0:
+ return False
+ return True
+
+
+def primes():
+ a = 1
+ while True:
+ if is_prime(a):
+ yield a
+ a += 1
+
+
+def alphabet_gen(string):
+ while True:
+ for char in string:
+ yield char
+
+
+def alphabet(code="", letters=""):
+ if code == "bg":
+ bgalphabet = "абвгдежзийклмнопрстуфхцчшщъьюя"
+ return alphabet_gen(bgalphabet)
+ if code == "lat":
+ latinalphabet = "abcdefghijklmnopqrstuvxyz"
+ return alphabet_gen(latinalphabet)
+ if code != "" and letters != "":
+ return alphabet_gen(letters)
+ if letters != "":
+ return alphabet_gen(letters)
+
+
+def intertwined_sequences(iter_object, generator_definitions={}):
+ generators = {}
+ for dic in iter_object:
+ if dic['sequence'] not in generators:
+ access = globals().copy()
+ access.update(locals())
+ current = None
+ if len(dic) <= 2:
+ if dic['sequence'] in generator_definitions:
+ current = iter(generator_definitions[dic['sequence']]())
+ else:
+ current = access.get(dic['sequence'])()
+ i = 0
+ while i < dic['length']:
+ yield next(current)
+ i += 1
+ generators[dic['sequence']] = current
+ else:
+ parametars = {}
+ for key in dic:
+ if key != 'sequence' and key != 'length':
+ parametars[key] = dic[key]
+ current = access.get(dic['sequence'])(**parametars)
+ i = 0
+ while i < dic['length']:
+ yield next(current)
+ i += 1
+ generators[dic['sequence']] = current
+ else:
+ i = 0
+ while i < dic['length']:
+ yield next(generators[dic['sequence']])
+ i += 1