Алтерниращ генератор

Краен срок
27.03.2014 23:59

Срокът за предаване на решения е отминал

Да се напише генератор alternate, който приема произволен брой аргументи, всеки от които връща обект итератор при извикването си. alternate се очаква да генерира обекти като взима последователно първите елементи от върнатите от аргументите итератори в същия ред, в който са подадени, после вторите, третите и т.н.

Примери

>>> mirror_count = alternate(lambda: itertools.count(1, 1), lambda: itertools.count(-1, -1))
>>> next(mirror_count)
1
>>> next(mirror_count)
-1
>>> next(mirror_count)
2
>>> next(mirror_count)
-2
>>> next(mirror_count)
3
>>> next(mirror_count)
-3
>>> next(mirror_count)
4

Решения

Станислав Гатев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Гатев
from itertools import cycle
def alternate(*iterators):
return (next() for next in cycle(iter(it()).__next__ for it in iterators))
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Стефани Цакова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стефани Цакова
def alternate (*args):
iterators = [iter(arg()) for arg in args]
while len(args):
i = 0
while i < len(iterators):
yield next(iterators[i])
i += 1
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Венцислав Велков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Велков
import itertools
def alternate(*functions):
iterators = [iter(f()) for f in functions]
while functions:
for i in iterators:
yield next(i)
raise StopIteration
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Иван Георгиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
from itertools import cycle
def alternate(*args):
iterators = cycle([iter(function()) for function in args])
while True:
yield next(next(iterators))
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Йосиф Цветков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Йосиф Цветков
import itertools
def alternate(*args):
iterators = itertools.cycle([generators() for generators in args])
while True:
yield next(next(iterators))
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Орлин Христов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Орлин Христов
from itertools import cycle
def alternate(*iterator_builders):
for iterator in cycle(builder() for builder in iterator_builders):
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Никола Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Димитров
def alternate(*args):
iterators = [func() for func in args]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Никола Ненков
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Никола Ненков
def alternate(*args):
for row_of_elements in zip(*map(lambda function: function(), args)):
for element in row_of_elements:
yield element
.F.
======================================================================
FAIL: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-ggnsmy/test.py", line 21, in test_with_finishing_iterable
    "He's coming in .."])
AssertionError: Lists differ: ["He's coming in ..", 3, "He's... != ["He's coming in ..", 3, "He's...

Second list contains 1 additional elements.
First extra element 6:
He's coming in ..

- ["He's coming in ..", 3, "He's coming in ..", 2, "He's coming in ..", 1]
+ ["He's coming in ..",
+  3,
+  "He's coming in ..",
+  2,
+  "He's coming in ..",
+  1,
+  "He's coming in .."]

----------------------------------------------------------------------
Ran 3 tests in 0.006s

FAILED (failures=1)
Стоян Ефтимов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Ефтимов
import itertools
def alternate(*arguments):
iterators = [argument() for argument in arguments]
cycle_iterators = itertools.cycle(iterators)
for iterator in cycle_iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Георги Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Димитров
def alternate(*args):
list_of_iterators = [arg() for arg in args]
while True:
for iterator in list_of_iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Драгомир Тунчев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Драгомир Тунчев
def alternate(*args):
args = [arg() for arg in args]
while True:
for element in (next(arg) for arg in args):
yield element
.E.
======================================================================
ERROR: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 57, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 3 tests in 2.092s

FAILED (errors=1)
Димитър Мутафчиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Мутафчиев
def alternate(*args):
args_iterators = [i() for i in args]
while True:
for i in args_iterators:
yield next(i)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Любомир Коев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Коев
def alternate(*arg):
iterables = [iter(iterable()) for iterable in arg]
while True:
for iterable in iterables:
yield next(iterable)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Цветелина Борисова
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Цветелина Борисова
import itertools
def alternate(*iterables):
pending = len(iterables)
nexts = itertools.cycle(iter(it()).__next__ for it in iterables)
while pending:
try:
for next in nexts:
yield next()
except StopIteration:
pending -= 1
nexts = itertools.cycle(islice(nexts, pending))
.E.
======================================================================
ERROR: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140415-23173-eygk0v/solution.py", line 10, in alternate
    yield next()
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-eygk0v/test.py", line 18, in test_with_finishing_iterable
    self.assertEqual(list(alternator), ["He's coming in ..", 3,
  File "/tmp/d20140415-23173-eygk0v/solution.py", line 13, in alternate
    nexts = itertools.cycle(islice(nexts, pending))
NameError: global name 'islice' is not defined

----------------------------------------------------------------------
Ran 3 tests in 0.005s

FAILED (errors=1)
Денис Бялев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Денис Бялев
def alternate(*elements):
value = 0
elements_list = [x() for x in elements]
while elements_list[value]:
while value <= len(elements) - 1:
yield next(elements_list[value])
value += 1
value = 0
raise StopIteration
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Божидар Михайлов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Божидар Михайлов
from itertools import chain
def alternate(*args):
def call(function): return function()
return chain.from_iterable(zip(*map(call, args)))
.F.
======================================================================
FAIL: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-11gswkb/test.py", line 21, in test_with_finishing_iterable
    "He's coming in .."])
AssertionError: Lists differ: ["He's coming in ..", 3, "He's... != ["He's coming in ..", 3, "He's...

Second list contains 1 additional elements.
First extra element 6:
He's coming in ..

- ["He's coming in ..", 3, "He's coming in ..", 2, "He's coming in ..", 1]
+ ["He's coming in ..",
+  3,
+  "He's coming in ..",
+  2,
+  "He's coming in ..",
+  1,
+  "He's coming in .."]

----------------------------------------------------------------------
Ran 3 tests in 0.006s

FAILED (failures=1)
Кирил Киров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кирил Киров
def alternate(*args):
next_loop_iteration_start = []
args = [arg() for arg in args]
while True:
for arg in args:
iterator = iter(arg)
generator_value = next(iterator)
next_loop_iteration_start.append(iterator)
yield generator_value
args = next_loop_iteration_start
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Тихомир Янев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Тихомир Янев
def alternate(*args):
storage = [x() for x in args]
while True:
for item in storage: yield next(item)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Васил Тодоров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Тодоров
import itertools
def alternate(*args):
iterators = [argument() for argument in args]
iterator_on_iterators = iter(iterators)
while True:
try:
it = next(iterator_on_iterators)
except(StopIteration):
iterator_on_iterators = iter(iterators)
it = next(iterator_on_iterators)
yield next(it)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Емилиан Станков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
def alternate(*arguments):
argument_iterators = []
for i in range(len(arguments)):
argument_iterators.append(iter(arguments[i]()))
while True:
for argument_iterator in argument_iterators:
yield next(argument_iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Веселин Генадиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Генадиев
from itertools import cycle
def alternate(*args):
iterators = [function() for function in args]
return (next(iterator) for iterator in cycle(iterators))
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Димитър Желев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Желев
def alternate(*arguments):
iterators = [iter(argument()) for argument in arguments]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Теодор Халваджиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Халваджиев
def alternate(*functions):
counters = [function() for function in functions]
i = 0
while True:
yield next(counters[i % len(counters)])
i += 1
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Ралица Цанова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Цанова
import itertools
def alternate(*arguments):
if len(arguments) == 0:
raise StopIteration
list_ = [argument() for argument in arguments]
index = 0
while True:
if index == len(list_):
index = 0
yield next(list_[index])
index += 1
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Петър Камбуров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Камбуров
import itertools
def alternate(*arg):
position = 0
iterators = {}
while position < len(arg):
iterators.setdefault(position, arg[position]())
yield next(iterators[position])
position += 1
if(position == len(arg)):
position = 0
...
----------------------------------------------------------------------
Ran 3 tests in 0.005s

OK
Йордан Дикманов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Дикманов
import itertools
def alternate(*functions):
if functions == (): raise StopIteration
iterators = []
for function in functions:
iterators.append(function())
while True:
for it in iterators:
function_result = next(it)
yield(function_result)
...
----------------------------------------------------------------------
Ran 3 tests in 0.048s

OK
Атанас Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
def alternate(*args):
iterators = [item() for item in args]
while iterators:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Лъчезар Николов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Лъчезар Николов
def alternate(*args):
iterators = [iter(function()) for function in args]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Иван Бобев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Бобев
from itertools import cycle
def alternate(*args):
iterators = (arg() for arg in args)
for iter in cycle(iterators):
yield next(iter)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Виктор Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Иванов
import itertools
def alternate(*args):
if len(args) == 0:
raise StopIteration
iterators = []
for arg in args:
iterators.append(arg())
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Атанас Филчев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Филчев
import itertools
def alternate(*args):
iterators = []
for iter in args:
i = iter()
iterators.append(i)
while True:
for iter in iterators:
yield(next(iter))
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Мартин Георгиев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Мартин Георгиев
import itertools
class alternate:
def __init__(self, iterator1, iterator2):
self.iterators = []
self.iterators.append(iterator1())
self.iterators.append(iterator2())
self.mode = 0
def __iter__(self):
return self
def __next__(self):
result = next(self.iterators[self.mode])
self.mode += 1
self.mode %= 2
return result
..E
======================================================================
ERROR: test_with_seven_iterables (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-1v21vha/test.py", line 30, in test_with_seven_iterables
    lambda: count(6, 7))
TypeError: __init__() takes 3 positional arguments but 8 were given

----------------------------------------------------------------------
Ran 3 tests in 0.006s

FAILED (errors=1)
Елена Димитрова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Димитрова
import itertools
def alternate(*args):
iterators = []
for generator in args:
iterators.append(generator())
counter = 0
loop_length = len(iterators)
if loop_length == 0:
raise StopIteration
while True:
yield next(iterators[counter % loop_length])
counter += 1
raise StopIteration
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Йончо Йончев
  • Некоректно
  • 0 успешни тест(а)
  • 3 неуспешни тест(а)
Йончо Йончев
from itertools import chain
def alternate(*iters):
return chain.from_iterable(zip(iters))
EFE
======================================================================
ERROR: test_mirror_count (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-qen9wd/test.py", line 12, in test_mirror_count
    [next(mirror_count) for i in range(1000)])
  File "/tmp/d20140415-23173-qen9wd/test.py", line 12, in <listcomp>
    [next(mirror_count) for i in range(1000)])
StopIteration

======================================================================
ERROR: test_with_seven_iterables (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-qen9wd/test.py", line 32, in test_with_seven_iterables
    [next(alternator) for i in range(49)])
  File "/tmp/d20140415-23173-qen9wd/test.py", line 32, in <listcomp>
    [next(alternator) for i in range(49)])
StopIteration

======================================================================
FAIL: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-qen9wd/test.py", line 21, in test_with_finishing_iterable
    "He's coming in .."])
AssertionError: Lists differ: [<function TestAlternatingGene... != ["He's coming in ..", 3, "He's...

First differing element 0:
<function TestAlternatingGenerator.test_with_finishing_iterable.<locals>.<lambda> at 0xb7828b24>
He's coming in ..

Second list contains 5 additional elements.
First extra element 2:
He's coming in ..

- [<function TestAlternatingGenerator.test_with_finishing_iterable.<locals>.<lambda> at 0xb7828b24>,
-  <function TestAlternatingGenerator.test_with_finishing_iterable.<locals>.<lambda> at 0xb7828bfc>]
+ ["He's coming in ..",
+  3,
+  "He's coming in ..",
+  2,
+  "He's coming in ..",
+  1,
+  "He's coming in .."]

----------------------------------------------------------------------
Ran 3 tests in 0.005s

FAILED (failures=1, errors=2)
Стефан Маринов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Маринов
from itertools import cycle
def alternate(*args):
for value in cycle(iter(argument()).__next__ for argument in args):
yield value()
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Весела Бандова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Весела Бандова
def alternate(*arg):
count = len(arg)
if count == 0:
return
generator_index = 0
next_elem = [0 for i in range(count)]
while 1:
generator = arg[generator_index]()
for i in range(next_elem[generator_index]):
next(generator)
yield next(generator)
next_elem[generator_index] += 1
generator_index = (generator_index + 1) % count
...
----------------------------------------------------------------------
Ran 3 tests in 0.080s

OK
Димитър Чаушев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Чаушев
import itertools
def alternate(*functions):
funcs = []
for function in functions:
funcs.append(iter(function()))
while True:
for element in funcs:
yield next(element)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Евгени Евлогиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Евгени Евлогиев
def alternate(*args):
if args == ():
raise StopIteration
iterators = []
for argument in args:
iterators.append(argument())
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Георги Стайков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Стайков
import itertools
def alternate(*arguments):
if len(arguments) == 0:
raise StopIteration
iterable_objects = {}
for i in range(0, len(arguments)):
iterable_objects[i] = arguments[i]()
index = 0
while True:
yield next(iterable_objects[index % len(arguments)])
index += 1
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Антонио Николов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Антонио Николов
import itertools
def alternate(*args):
if len(args) == 0:
raise StopIteration
iterators = [iterator() for iterator in args]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Александър Златков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Златков
def alternate(*args):
iterators = [arg() for arg in args]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Димитър Трендафилов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Трендафилов
import itertools
def alternate(*args):
args = tuple([_() for _ in args])
if len(args) == 0:
raise StopIteration
while True:
for current in args:
yield next(current)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Деян Камбуров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Камбуров
def alternate(*functions):
iterators = [function() for function in functions]
while True:
for iterator in iterators:
iterator = next(iterator)
yield iterator
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Данаил Койчев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Данаил Койчев
def alternate(*iterator_creators):
iterators = [iterator_creator() for iterator_creator in iterator_creators]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Ангел Цанев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Цанев
def alternate(*args):
if len(args) == 0:
raise StopIteration
iterators = [function() for function in args]
while(True):
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Константин Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Димитров
import itertools
def alternate(*arg):
interabals = []
for lam in arg:
interabals.append(lam())
while 1:
for inter in interabals:
yield next(inter)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Гергана Петрова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Гергана Петрова
from itertools import cycle
def alternate(*args):
return (next(argument) for argument in cycle([arg() for arg in args]))
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Пламен Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Пламен Димитров
import itertools
def alternate(*arg):
iterators = [i() for i in arg]
cycle_list = itertools.cycle(iterators)
while True:
yield next(next(cycle_list))
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Стоян Христов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Христов
from itertools import cycle
def alternate(*args):
iterators = cycle([argument() for argument in args])
while True:
yield next(next(iterators))
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Георги Янев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Янев
def alternate(*args):
iter_functions = [arg() for arg in args]
while True:
for iter_function in iter_functions:
yield next(iter_function)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Момчил Станчев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Момчил Станчев
import itertools
def alternate(*args):
generators = []
for arg in args:
generators.append(arg())
index = 0
while True:
yield next(generators[index])
index += 1
index %= len(generators)
return StopIteration
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Снежана Спасова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Снежана Спасова
def alternate(*args):
iterators = list(map(lambda x: x(), args))
count_times_yield = 0
while True:
if count_times_yield < len(args):
yield next(iterators[count_times_yield])
count_times_yield += 1
else:
count_times_yield = 0
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Ирина Иванова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ирина Иванова
import itertools
def alternate(*arguments):
iterators = [x() for x in arguments]
count = 0
while True:
yield next(iterators[count])
count += 1
if count == len(iterators):
count = 0
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Филип Митов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Филип Митов
def alternate(*arguments):
all_arguments = [one_function() for one_function in arguments]
while True and arguments:
for index in range(len(arguments)):
yield next(all_arguments[index])
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Валентин Петров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Петров
def alternate(*args):
iter = [ i() for i in args]
while True:
for x in iter:
yield next(x)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Стефан Колчев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Стефан Колчев
import itertools
def alternate(*arg):
iterables = [argument() for argument in arg]
iterable_tuples = zip(*iterables)
for iterable_tuple in iterable_tuples:
for item in iter(iterable_tuple):
yield item
.F.
======================================================================
FAIL: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-rp440l/test.py", line 21, in test_with_finishing_iterable
    "He's coming in .."])
AssertionError: Lists differ: ["He's coming in ..", 3, "He's... != ["He's coming in ..", 3, "He's...

Second list contains 1 additional elements.
First extra element 6:
He's coming in ..

- ["He's coming in ..", 3, "He's coming in ..", 2, "He's coming in ..", 1]
+ ["He's coming in ..",
+  3,
+  "He's coming in ..",
+  2,
+  "He's coming in ..",
+  1,
+  "He's coming in .."]

----------------------------------------------------------------------
Ran 3 tests in 0.005s

FAILED (failures=1)
Милица Борисова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Милица Борисова
def alternate(*args):
if len(args) > 0:
iterable_arguments = [argument() for argument in args]
while True:
for iterable_item in iterable_arguments:
yield next(iterable_item)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Мария Кърчева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Кърчева
def alternate (*arguments):
iterators = [argument() for argument in arguments]
i = 0
while True:
yield next(iterators[i])
i = (i + 1) % len(iterators)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Божидар Карааргиров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Карааргиров
def alternate(*args):
if len(args) is 0:
raise StopIteration
iterators = [iterator() for iterator in args]
while True:
for i in iterators:
yield next(i)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Владимир Начев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Владимир Начев
import itertools
def alternate(*args):
iterable = itertools.cycle([_() for _ in args])
for iterator in iterable:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Теодор Драганов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Драганов
def alternate(*args):
iterators_from_args = list(map(lambda x: x(), args))
while True and args:
for iter_object in iterators_from_args:
yield next(iter_object)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Стоян Цветков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стоян Цветков
import itertools
def alternate(*args):
if len(args) == 0:
raise StopIteration
next_to_call = 0
generators = []
for argument in args:
generators.append(argument())
get_next_from_generator = lambda generator: next(generator)
while True:
yield get_next_from_generator(generators[next_to_call])
next_to_call += 1
if next_to_call >= len(generators):
next_to_call = 0
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Иван Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Иванов
import itertools
def alternate(*kwargs):
iterator = []
for arg in kwargs:
iterator.append(arg())
current_iterator = 0
while True:
yield next(iterator[current_iterator])
current_iterator += 1
if current_iterator == len(iterator):
current_iterator = 0
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Мария Донева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Донева
def alternate(*args):
iterible = []
for argument in args:
iterator = iter(argument())
iterible.append(iterator)
while True:
for iterator in iterible:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Дарина Кръстева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Дарина Кръстева
import itertools
def alternate(*args):
iterators = []
for function in args:
iterators.append(function())
iterators_cycled = itertools.cycle(iterators)
while True:
yield next(next(iterators_cycled))
raise StopIteration
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Елица Илиева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Елица Илиева
import itertools
def alternate(*args):
args = itertools.cycle(i() for i in args)
for i in args:
yield next(i)
...
----------------------------------------------------------------------
Ran 3 tests in 0.097s

OK
Иван Върбанов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Иван Върбанов
import itertools
def alternate(*args):
arguments = []
for argument in args:
arguments.append(iter(argument()))
while True:
for argument in arguments:
for other_arguments in argument:
yield other_arguments
break
.E.
======================================================================
ERROR: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 57, in thread
    raise TimeoutError
TimeoutError

----------------------------------------------------------------------
Ran 3 tests in 2.059s

FAILED (errors=1)
Атанас Пройчев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Пройчев
def alternate(*functions):
iterators = [function() for function in functions]
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Найден Найдев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Найден Найдев
def alternate(*args):
iter_args = [arg() for arg in args]
while True:
for it in iter_args:
yield next(it)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Даяна Маринова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Даяна Маринова
import itertools
def alternate(*functions):
iterators = [iter(f()) for f in functions]
while True:
for iters in iterators:
yield next(iters)
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Марио Даскалов
  • Некоректно
  • 0 успешни тест(а)
  • 3 неуспешни тест(а)
Марио Даскалов
from itertools import repeat, chain
def alternate(*generator_functions):
generators = {}
for generator_function in chain.from_iterable(repeat(generator_functions)):
if generator_function not in generators:
generators[generator_function] = generator_function()
yield next(generators[generator_function])
EEE
======================================================================
ERROR: test_mirror_count (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 57, in thread
    raise TimeoutError
TimeoutError

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

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

----------------------------------------------------------------------
Ran 3 tests in 6.221s

FAILED (errors=3)
Николай Масларски
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Масларски
import itertools
def alternate(*args):
iterators = []
for function in args:
iterators.append(function())
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Теодора Добрева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Теодора Добрева
def alternate(*args):
arguments_length = len(args)
argument_index = 0
functions = []
for function in args:
functions.append(function())
while True:
yield next(functions[argument_index % arguments_length])
argument_index += 1
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Марио Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Димитров
import itertools
def alternate(*args):
func_iters = []
val_iters = []
args_iter = iter(args)
for i in range(0, len(args)):
func_iters.append(next(args_iter))
val_iters.append(iter(func_iters[i]()))
index = 0
while True:
if index == len(args):
index = 0
yield next(val_iters[index])
index += 1
...
----------------------------------------------------------------------
Ran 3 tests in 0.004s

OK
Велина Дойчева
  • Некоректно
  • 0 успешни тест(а)
  • 3 неуспешни тест(а)
Велина Дойчева
def alternate(*iterators):
sentinel = object()
for it in iterators:
elem = next(it, sentinel)
if elem is sentinel:
return
yield elem
EEE
======================================================================
ERROR: test_mirror_count (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-168ksiq/test.py", line 12, in test_mirror_count
    [next(mirror_count) for i in range(1000)])
  File "/tmp/d20140415-23173-168ksiq/test.py", line 12, in <listcomp>
    [next(mirror_count) for i in range(1000)])
  File "/tmp/d20140415-23173-168ksiq/solution.py", line 4, in alternate
    elem = next(it, sentinel)
TypeError: 'function' object is not an iterator

======================================================================
ERROR: test_with_finishing_iterable (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-168ksiq/test.py", line 18, in test_with_finishing_iterable
    self.assertEqual(list(alternator), ["He's coming in ..", 3,
  File "/tmp/d20140415-23173-168ksiq/solution.py", line 4, in alternate
    elem = next(it, sentinel)
TypeError: 'function' object is not an iterator

======================================================================
ERROR: test_with_seven_iterables (test.TestAlternatingGenerator)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140415-23173-168ksiq/test.py", line 32, in test_with_seven_iterables
    [next(alternator) for i in range(49)])
  File "/tmp/d20140415-23173-168ksiq/test.py", line 32, in <listcomp>
    [next(alternator) for i in range(49)])
  File "/tmp/d20140415-23173-168ksiq/solution.py", line 4, in alternate
    elem = next(it, sentinel)
TypeError: 'function' object is not an iterator

----------------------------------------------------------------------
Ran 3 tests in 0.004s

FAILED (errors=3)
Ивайло Дянков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Дянков
def alternate(*args):
iterators = list()
for arg in args:
iterators.append(arg())
while True:
for iterator in iterators:
yield next(iterator)
...
----------------------------------------------------------------------
Ran 3 tests in 0.012s

OK