Кристиан обнови решението на 03.04.2015 02:02 (преди над 9 години)
+import math
+from itertools import chain, islice, count
+
+
+def fibonacci():
+ prev, current = 0, 1
+ while True:
+ yield current
+ prev, current = current, prev + current
+
+
+def primes():
+ for n in count(2):
+ if is_prime(n):
+ yield n
+
+
+def is_prime(number):
+ square_root = int(math.sqrt(number) + 1)
+ for divisor in range(2, square_root):
+ if number % divisor == 0:
+ return False
+ return True
+
+
+LETTERS = {
+ 'lat': 'abcdefzhiklmnopqrstvx',
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'}
+
+
+def alphabet(*, code=None, letters=None):
+ if code is not None and letters is None:
+ return iter(LETTERS[code])
+ elif letters is not None:
+ return iter(letters)
+
+
+def intertwined_sequences(iterable):
+ result = iter(())
+ for wrap in iterable:
+ if wrap['sequence'] == 'alphabet':
+ result = chain(result, alphabet_generator(wrap))
+ else:
+ result = chain(result, other_generator(wrap))
+ return result
+
+
+def alphabet_generator(wrap):
+ method_name = globals()[wrap['sequence']]
+ length = int(wrap['length'])
+ if 'letters' in wrap:
+ alphabet_iter = islice(method_name(letters=wrap['letters']), length)
+ else:
+ alphabet_iter = islice(method_name(code=wrap['code']), length)
+ return (letter for letter in alphabet_iter)
+
+
+def other_generator(wrap):
+ method_name = globals()[wrap['sequence']]
+ length = int(wrap['length'])
+ other_iter = islice(method_name(), length)
+ return (number for number in other_iter)