Валентина обнови решението на 02.04.2015 12:28 (преди над 9 години)
+from math import sqrt
+from math import ceil
+
+
+def fibonacci():
+ preceding1 = 1
+ yield preceding1
+ preceding2 = 1
+ yield preceding2
+ while True:
+ current = preceding1 + preceding2
+ preceding1 = preceding2
+ preceding2 = current
+ yield current
+
+
+def is_prime(number):
+ if abs(number) in [0, 1]:
+ return False
+ elif abs(number) == 2:
+ return True
+ return not [divider for divider in range(2, ceil(sqrt(abs(number))) + 1)
+ if not (abs(number) % divider)]
+
+
+def primes():
+ number = 2
+ while True:
+ if is_prime(number):
+ yield number
+ number += 1
+
+
+def alphabet(letters=None, code=None):
+ if letters:
+ for letter in letters:
+ yield letter
+ elif code == 'lat':
+ for letter in "abcdefghijklmnopqrstuvwxyz":
+ yield letter
+ elif code == 'bg':
+ for letter in "абвгдежзийклмнопрстуфхцчшщъьюя":
+ yield letter
+
+
+def intertwined_sequences(sequences, generator_definitions={}):
+ iterators = {}
+ sequence = iter(sequences)
+ while True:
+ current = next(sequence)
+ generator = current["sequence"]
+ if generator not in iterators:
+ arguments = {key: value for key, value in current.items()
+ if key not in ["sequence", "length"]}
+ if generator in generator_definitions:
+ iterators[generator] = iter(
+ generator_definitions[generator](**arguments))
+ elif generator in globals():
+ iterators[generator] = iter(globals()[generator](**arguments))
+ for counter in range(current["length"]):
+ yield next(iterators[generator])