Решение на Генератори и итератори от Иванна Димитрова

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

Към профила на Иванна Димитрова

Резултати

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

Код

def primes():
n = 2
primes = set()
while True:
for p in primes:
if n % p == 0:
break
else:
primes.add(n)
yield n
n += 1
a,b = 0,1
def fibonacci():
global a,b
while True:
a,b = b, a+b
yield a
import string
lat = iter(list(string.ascii_lowercase))
bg = iter(list('абвгдежзийклмнопрстуфхцчшщъьюя'))
def alphabet(code="" , letters=""):
if code == 'lat':
for i in lat:
yield i
elif code == 'bg':
for i in bg:
yield i
else:
for i in letters:
yield i
from itertools import cycle
def endless_growing_sequences():
for i, generator_key in enumerate(cycle(['fibonacci', 'primes'])):
yield {'sequence': generator_key, 'length': i + 1}
def intertwined_sequences(sequence):
i = 1
j = 0
for tup in sequence:
tup_iter = next (iter (tup.values()))
tup_iter_next = next (tup_iter)
if tup_iter is not 'alphabet':
for method_name, how_many_times in zip(tup_iter,tup_iter_next):
possibles = globals().copy()
possibles.update(locals())
method = possibles.get(method_name)()
while (i <= int(how_many_times)):
i += 1
print (method)
else: #is alphabet
for code, how_many in zip(tup_iter,tup_iter_next):
while (j <= int(how_many)):
j += 1
print (alphabet(code))

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

......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 12.355s

FAILED (errors=6)

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

Иванна обнови решението на 03.04.2015 09:44 (преди около 9 години)

+def primes():
+ n = 2
+ primes = set()
+ while True:
+ for p in primes:
+ if n % p == 0:
+ break
+ else:
+ primes.add(n)
+ yield n
+ n += 1
+
+
+a,b = 0,1
+def fibonacci():
+ global a,b
+ while True:
+ a,b = b, a+b
+ yield a
+
+
+
+import string
+lat = iter(list(string.ascii_lowercase))
+bg = iter(list('абвгдежзийклмнопрстуфхцчшщъьюя'))
+
+def alphabet(code="" , letters=""):
+ if code == 'lat':
+ for i in lat:
+ yield i
+ elif code == 'bg':
+ for i in bg:
+ yield i
+ else:
+ for i in letters:
+ yield i
+def intertwined_sequences(sequence):
+ i = 1
+ j = 0
+ for tup in sequence:
+ tup_iter = next (iter (tup.values()))
+ tup_iter_next = next (tup_iter)
+ if tup_iter is not 'alphabet':
+ for method_name, how_many_times in zip(tup_iter,tup_iter_next):
+ possibles = globals().copy()
+ possibles.update(locals())
+ method = possibles.get(method_name)()
+ while (i <= int(how_many_times)):
+ i += 1
+ print (method)
+
+ else: #is alphabet
+ for code, how_many in zip(tup_iter,tup_iter_next):
+ while (j <= int(how_many)):
+ j += 1
+ print (alphabet(code))

Иванна обнови решението на 03.04.2015 09:49 (преди около 9 години)

def primes():
n = 2
primes = set()
while True:
for p in primes:
if n % p == 0:
break
else:
primes.add(n)
yield n
n += 1
a,b = 0,1
def fibonacci():
global a,b
while True:
a,b = b, a+b
yield a
import string
lat = iter(list(string.ascii_lowercase))
bg = iter(list('абвгдежзийклмнопрстуфхцчшщъьюя'))
def alphabet(code="" , letters=""):
if code == 'lat':
for i in lat:
yield i
elif code == 'bg':
for i in bg:
yield i
else:
for i in letters:
yield i
+
+from itertools import cycle
+def endless_growing_sequences():
+ for i, generator_key in enumerate(cycle(['fibonacci', 'primes'])):
+ yield {'sequence': generator_key, 'length': i + 1}
+
+
def intertwined_sequences(sequence):
i = 1
j = 0
for tup in sequence:
tup_iter = next (iter (tup.values()))
tup_iter_next = next (tup_iter)
if tup_iter is not 'alphabet':
for method_name, how_many_times in zip(tup_iter,tup_iter_next):
possibles = globals().copy()
possibles.update(locals())
method = possibles.get(method_name)()
while (i <= int(how_many_times)):
i += 1
print (method)
else: #is alphabet
for code, how_many in zip(tup_iter,tup_iter_next):
while (j <= int(how_many)):
j += 1
print (alphabet(code))