Емине обнови решението на 03.04.2015 02:58 (преди над 9 години)
+from itertools import islice
+
+
+def fibonacci(a=1, b=1):
+ while True:
+ yield a
+ next_fib = a + b
+ a = b
+ b = next_fib
+
+
+def is_prime(num):
+ for j in range(2, num):
+ if (num % j) == 0:
+ return False
+ return True
+
+
+def primes(i=2):
+ while True:
+ if is_prime(i):
+ yield i
+ i += 1
+
+
+def alphabet(code='', letters=''):
+ alph = ''
+ if code == 'lat' and letters == '':
+ alph = 'abcdefghijklmnopqrstuvwxyz'
+ elif code == 'bg' and letters == '':
+ alph = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ else:
+ alph = letters
+
+ for i in range(len(alph)):
+ yield alph[i]
+
+
+def intertwined_sequences(sequences=()):
+ for i in range(len(sequences)):
+ seq = sequences[i]['sequence']
+ length = sequences[i]['length']
+ result = []
+
+ if seq == 'fibonacci':
+ result.extend(list(islice(fibonacci(), length)))
+ elif seq == 'primes':
+ result.extend(list(islice(primes(), length)))
+ elif seq == 'alphabet':
+ seq_code = sequences[i]['code']
+ result.extend(list(islice(alphabet(code=seq_code), length)))
+
+ for j in range(len(result)):
+ yield result[j]