Божидар обнови решението на 03.04.2015 14:37 (преди над 9 години)
+import math
+
+
+lat_alphabet = 'abcdefghijklmnopqrstuvwxyz'
+bg_alphabet = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+
+
+def fibonacci():
+ temporary = 1
+ element = 1
+ yield temporary
+ while True:
+ temporary, element = element, temporary + element
+ yield temporary
+
+
+def is_prime(number):
+ limit = int(math.sqrt(number)+1)
+ for index in range(2,limit):
+ if number % index == 0:
+ return False
+ return True
+
+
+def primes():
+ temporary = 2;
+ while True:
+ if is_prime(temporary):
+ yield temporary
+ temporary += 1
+
+
+def alphabet(**kwargs):
+
+ if kwargs.get('letters'):
+ for index in range(0,len(kwargs.get('letters'))):
+ yield (kwargs.get('letters'))[index]
+
+ if kwargs.get('code') == 'lat':
+ for index in range(0,len(lat_alphabet)):
+ yield lat_alphabet[index]
+ elif kwargs.get('code') == 'bg':
+ for index in range(0,len(bg_alphabet)):
+ yield bg_alphabet[index]
+
+
+def intertwined_sequences(*args,**kwargs):
+ elements = []
+ sequences = {}
+ custom_gens = kwargs.get('generator_definitions')
+ for params in args:
+ for param in params:
+ name = param.pop('sequence')
+ iterations = param.pop('length')
+ sequence = sequences.get(name)
+ if sequence is None:
+ func = globals().get(name)
+ if func is None:
+ func = custom_gens.get(name)
+ if len(param) == 0:
+ sequence = iter(func())
+ else:
+ sequence = iter(func(**param))
+ sequences[name] = sequence
+
+ for index in range(0,iterations):
+ elements.append(next(sequence))
+ return elements