Никола обнови решението на 02.04.2015 22:36 (преди над 9 години)
+from argparse import ArgumentError
+
+
+def fibonacci():
+ prev, nxt = 1, 1
+
+ while True:
+ yield prev
+ prev, nxt = nxt, prev + nxt
+
+
+def primes():
+ number = 1
+
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def is_prime(n):
+ if n <= 3:
+ return n >= 2
+ if n % 2 == 0 or n % 3 == 0:
+ return False
+ for i in range(5, int(n ** 0.5) + 1, 6):
+ if n % i == 0 or n % (i + 2) == 0:
+ return False
+ return True
+
+
+def alphabet(*, code='lat', letters=False):
+ lat_letters = 'abcdefghijklmnopqrstuvwxyz'
+ bg_letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ used_letters = ''
+ if letters is not False:
+ used_letters = letters
+ elif code == 'lat':
+ used_letters = lat_letters
+ elif code == 'bg':
+ used_letters = bg_letters
+ else:
+ raise ArgumentError
+
+ for letter in used_letters:
+ yield letter
+
+
+def intertwined_sequences(generators, *, generator_definitions={}):
+ iterators = {}
+
+ for generator in generators:
+ if generator['sequence'] not in iterators.keys():
+ iterator_args = {}
+
+ for seq_arg in generator:
+ if seq_arg is not 'sequence' and seq_arg is not 'length':
+ iterator_args.update({seq_arg: generator[seq_arg]})
+
+ if generator['sequence'] in generator_definitions:
+ generated_iterator = generator_definitions[generator['sequence']](**iterator_args)
+ else:
+ generated_iterator = globals()[generator['sequence']](**iterator_args)
+ iterators.update({generator['sequence']: generated_iterator})
+
+ for iteration in range(generator['length']):
+ yield next(iterators[generator['sequence']])