Решение на Генератори и итератори от Божидар Григоров

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

Към профила на Божидар Григоров

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 8 успешни тест(а)
  • 6 неуспешни тест(а)

Код

def fibonacci():
a, b = 1, 0
while True:
yield a
a, b = a + b, a
def is_prime(n):
return all(n % i for i in range(2, n))
def primes():
n = 2
while True:
if is_prime(n):
yield n
n += 1
alphabets = {
'lat': 'abcdefghijklmnopqrstuvwxyz',
'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'
}
def alphabet(code='lat', letters=None):
if letters is None:
for char in alphabets[code]:
yield char
else:
for char in letters:
yield char

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

......EEEEEE..
======================================================================
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

----------------------------------------------------------------------
Ran 14 tests in 13.685s

FAILED (errors=6)

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

Божидар обнови решението на 03.04.2015 12:59 (преди над 9 години)

+def fibonacci():
+ a, b = 1, 0
+ while True:
+ yield a
+ a, b = a + b, a
+
+
+def is_prime(n):
+ return all(n % i for i in range(2, n))
+
+
+def primes():
+ n = 2
+ while True:
+ if is_prime(n):
+ yield n
+ n += 1
+
+alphabets = {
+ 'lat': 'abcdefghijklmnopqrstuvwxyz',
+ 'bg': 'абвгдежзийклмнопрстуфхцчшщъьюя'
+}
+
+
+def alphabet(code='lat', letters=None):
+ if letters is None:
+ for char in alphabets[code]:
+ yield char
+ else:
+ for char in letters:
+ yield char