Вера обнови решението на 03.04.2015 14:03 (преди над 9 години)
+def fibonacci():
+ counter = 0
+ while True:
+ if counter == 0 or counter == 1:
+ yield 1
+ counter += 1
+ else:
+ number1 = 1
+ number2 = 1
+ while True:
+ yield number1 + number2
+ temp = number2
+ number2 = number1 + number2
+ number1 = temp
+
+
+
+def primes():
+ def isPrime(x):
+ if x == 1 or x == 2:
+ return True
+ elif x % 2 == 0:
+ return False
+ else:
+ d = x/2
+ while d > 1:
+ if d % 2 == 0:
+ return False
+ d -= 1
+ return True
+ num = 1
+ while True:
+ if isPrime(num) == True:
+ yield num
+ num += 1
+
+
+def alphabet(code='', letters=''):
+ if code == "bg":
+ item = list("абвгдежзийклмнопрстуфхцчшщъьюя")
+ elif code == "lat":
+ item = list("abcdefghijklmnopqrstuvwxyz")
+ else:
+ item = letters
+ for letter in item:
+ yield letter
+result = alphabet("bg")
+
+
+def intertwined_sequences(*dict_arguments):
+ dictionaries = list(dict_arguments)
+ result = []
+
+ def helper(dict):
+ if dict['sequence'] == 'fibonacci':
+ result_item = fibonacci()
+ elif dict['sequence'] == 'primes':
+ result_item = primes()
+ elif dict['sequence'] == 'alphabet':
+ result_item = alphabet(dict['code'])
+ num = dict['length']
+ while num > 0:
+ result.append(next(result_item))
+ num -= 1
+ return result
+ for dict in dictionaries:
+ if (dict != ''):
+ yield helper(dict)