Христо обнови решението на 03.04.2015 16:52 (преди над 9 години)
+from math import *
+
+
+def fibonacci():
+ n = 0
+ while True:
+ fi = (1 + sqrt(5)) / 2
+ yield int((pow(fi, n) - pow(-fi, -n)) / sqrt(5))
+ n += 1
+
+
+def is_prime(number):
+ for i in range(2, number):
+ if number % 2 == 0:
+ return False
+ return True
+
+
+def primes():
+ n = 2
+ while True:
+ if is_prime(n):
+ yield n
+ n += 1
+
+
+def alphabet(code='', letters=''):
+ if code != '':
+ if code == 'bg':
+ lower = [chr(i) for i in range(ord('а'), ord('я') + 1)]
+ lower.remove('ы')
+ lower.remove('ь')
+ lower.remove('э')
+ return iter(lower)
+ else:
+ lower = [chr(i) for i in range(ord('a'), ord('z') + 1)]
+ lower.remove('j')
+ lower.remove('u')
+ lower.remove('w')
+ return iter(lower)
+ elif letters != '' and code == '':
+ return iter(letters)
+
+
+def intertwined_sequences(iter_obj, generator_definitions=dict()):
+ mix_iterator = list()
+ dictionary = dict()
+ dictionary.update({'fibonacci': fibonacci})
+ dictionary.update({'primes': primes})
+ dictionary.update({'alphabet': alphabet})
+ dictionary.update(generator_definitions)
+ for item in iter_obj:
+ if item['sequence'] != 'alphabet':
+ seq = dictionary[item['sequence']]()
+ mix_iterator.extend([next(seq) for _ in range(item['length'])])
+ else:
+ if 'code' in item:
+ seq = dictionary['alphabet'](code=item['code'])
+ mix_iterator.extend([next(seq) for _ in range(item['length'])])
+ else:
+ seq = dictionary['alphabet'](letters=item['letters'])
+ mix_iterator.extend([next(seq) for _ in range(item['length'])])
+ return iter(mix_iterator)