Решение на Генератори и итератори от Павел Павлов

Обратно към всички решения

Към профила на Павел Павлов

Резултати

  • 2 точки от тестове
  • 0 бонус точки
  • 2 точки общо
  • 3 успешни тест(а)
  • 11 неуспешни тест(а)

Код

def fibonacci():
last_num = 0
present_num = 1
value = 0
while True:
if last_num == 0 and value < 1:
yield last_num + present_num
value = 1
else:
yield last_num + present_num
num = present_num
present_num += last_num
last_num = num
raise StopIteration
def primes():
is_prime_num = 3
yield 2
while True:
l = map(lambda x: is_prime_num % x != 0, range(2, is_prime_num))
if all(list(l)):
yield is_prime_num
is_prime_num += 1
raise StopIteration
def alphabet(code):
letters = {'lat' : ['a', 'b', 'c', 'd', 'e', 'f', 'j', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z'],
'bul' : ['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к',
'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у'
'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ь', 'ю', 'я']}
alphabet_letters = letters.get(code)
for letter in alphabet_letters:
yield letter
raise StopIteration

Лог от изпълнението

EEEE..EEEEEEE.
======================================================================
ERROR: test_bg_alphabet (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_endless_letters_generator (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_glagolitic (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_lat_alphabet (test.TestAlphabet)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_generator_definitions (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_infinite_intertwined (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_intertwine (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_intertwine_repeating_builtin (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_kwargs_generator (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_repeating_with_different_args (test.TestIntertwine)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

======================================================================
ERROR: test_for_larger_prime (test.TestPrimes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 65, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 14 tests in 22.170s

FAILED (errors=11)

История (1 версия и 0 коментара)

Павел обнови решението на 03.04.2015 16:57 (преди почти 9 години)

+def fibonacci():
+ last_num = 0
+ present_num = 1
+ value = 0
+ while True:
+ if last_num == 0 and value < 1:
+ yield last_num + present_num
+ value = 1
+ else:
+ yield last_num + present_num
+ num = present_num
+ present_num += last_num
+ last_num = num
+ raise StopIteration
+
+
+def primes():
+ is_prime_num = 3
+ yield 2
+ while True:
+ l = map(lambda x: is_prime_num % x != 0, range(2, is_prime_num))
+ if all(list(l)):
+ yield is_prime_num
+ is_prime_num += 1
+ raise StopIteration
+
+
+def alphabet(code):
+ letters = {'lat' : ['a', 'b', 'c', 'd', 'e', 'f', 'j', 'h', 'i', 'j', 'k',
+ 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
+ 'u', 'v', 'w', 'x', 'y', 'z'],
+ 'bul' : ['а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к',
+ 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у'
+ 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ь', 'ю', 'я']}
+ alphabet_letters = letters.get(code)
+ for letter in alphabet_letters:
+ yield letter
+ raise StopIteration