Станислав обнови решението на 30.03.2015 23:34 (преди над 9 години)
+from collections import Iterable
+
+LATIN_ALPHABET = 'abcdefghijklmnopqrstuvw'
+CYRILLIC_ALPHABET = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+
+
+def fibonacci():
+ last_number = 0
+ next_number = 1
+ while True:
+ yield next_number
+ last_number = next_number+last_number
+ yield last_number
+ next_number = next_number+last_number
+
+
+def primes():
+ def is_prime(number):
+ if (number == 2):
+ return True
+ if (number % 2 == 0):
+ return False
+ for factor in range(3, 1+int(round(number**0.5)), 2):
+ if (number % factor == 0):
+ return False
+ return True
+ number = 2
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def alphabet(code='lat', letters=False):
+ if not isinstance(letters, Iterable):
+ if code is 'lat':
+ letters = LATIN_ALPHABET
+ elif code is 'bg':
+ letters = CYRILLIC_ALPHABET
+ else:
+ return None
+
+ counter = 0
+ while True:
+ yield letters[counter]
+ counter += 1
+
+
+def intertwined_sequences(iterable_object, generator_definitions={}):
+
+ for elem in iterable_object:
+ length = elem['length']
+ if elem['sequence'] is 'alphabet':
+ if elem.get('letters'):
+ key = elem.get('letters')
+ gen = eval('alphabet(letters="{}")'.format(key))
+ elif elem.get('code'):
+ key = elem.get('code')
+ gen = eval('alphabet(code="{}")'.format(key))
+
+ if not generator_definitions.get(key):
+ generator_definitions.update({key: gen})
+ else:
+ gen = generator_definitions[key]
+ else:
+
+ key = elem['sequence']
+ if not generator_definitions.get(key):
+ del(elem['sequence'])
+ del(elem['length'])
+ gen = eval('{}({})'.format(key, ', '.join(list(elem))))
+ generator_definitions.update({key: gen})
+ else:
+ gen = generator_definitions[key]
+
+ for _ in range(length):
+ yield next(gen)