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

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

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

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 13 успешни тест(а)
  • 1 неуспешни тест(а)

Код

def fibonacci():
current, later = 1, 1
while True:
yield current
current, later = later, later + current
def primes():
dividers = {}
x = 2
while True:
if x not in dividers:
yield x
dividers[x*x] = [x]
else:
for d in dividers[x]:
dividers.setdefault(d + x, []).append(d)
del dividers[x]
x += 1
def alphabet(**kwargs):
if 'letters' in kwargs:
letters = kwargs['letters']
elif 'code' in kwargs:
if kwargs['code'] is 'bg':
letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
elif kwargs['code'] is 'lat':
letters = 'abcdefghijklmnopqrstuvwxyz'
for letter in letters:
yield letter
def intertwined_sequences(sequences, generator_definitions=None):
generators = {}
for s in sequences:
sequence = s.pop('sequence')
length = s.pop('length')
if sequence not in generators.keys():
if sequence in globals():
generators[sequence] = globals()[sequence](**s)
else:
generators[sequence] = generator_definitions[sequence](**s)
for _ in range(length):
yield next(generators[sequence])

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

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

----------------------------------------------------------------------
Ran 14 tests in 2.189s

FAILED (errors=1)

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

Георги обнови решението на 02.04.2015 19:48 (преди над 9 години)

+def fibonacci():
+ current, next = 1, 1
+ while True:
+ yield current
+ current, next = next, next + current
+
+
+def primes():
+ deviders = {}
+ x = 2
+ while True:
+ if x not in deviders:
+ yield x
+ deviders[x*x] = [x]
+ else:
+ for d in deviders[x]:
+ deviders.setdefault(d + x, []).append(d)
+ del deviders[x]
+ x += 1
+
+
+def alphabet(**kwargs):
+ if 'letters' in kwargs:
+ letters = kwargs['letters']
+ elif 'code' in kwargs:
+ if kwargs['code'] is 'bg':
+ letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
+ elif kwargs['code'] is 'lat':
+ letters = 'abcdefghijklmnopqrstuvwxyz'
+ for letter in letters:
+ yield letter
+
+
+def intertwined_sequences(sequences, generator_definitions=None):
+ generators = {}
+ for s in sequences:
+ sequence = s.pop('sequence')
+ length = s.pop('length')
+ if sequence not in generators.keys():
+ if sequence in globals():
+ generators[sequence] = globals()[sequence](**s)
+ else:
+ generators[sequence] = generator_definitions[sequence](**s)
+ for _ in range(length):
+ yield next(generators[sequence])

Георги обнови решението на 03.04.2015 02:05 (преди над 9 години)

def fibonacci():
- current, next = 1, 1
+ current, later = 1, 1
while True:
yield current
- current, next = next, next + current
+ current, later = later, later + current
def primes():
deviders = {}
x = 2
while True:
if x not in deviders:
yield x
deviders[x*x] = [x]
else:
for d in deviders[x]:
deviders.setdefault(d + x, []).append(d)
del deviders[x]
x += 1
def alphabet(**kwargs):
if 'letters' in kwargs:
letters = kwargs['letters']
elif 'code' in kwargs:
if kwargs['code'] is 'bg':
letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
elif kwargs['code'] is 'lat':
letters = 'abcdefghijklmnopqrstuvwxyz'
for letter in letters:
yield letter
def intertwined_sequences(sequences, generator_definitions=None):
generators = {}
for s in sequences:
sequence = s.pop('sequence')
length = s.pop('length')
if sequence not in generators.keys():
if sequence in globals():
generators[sequence] = globals()[sequence](**s)
else:
generators[sequence] = generator_definitions[sequence](**s)
for _ in range(length):
yield next(generators[sequence])

Георги обнови решението на 03.04.2015 02:07 (преди над 9 години)

def fibonacci():
current, later = 1, 1
while True:
yield current
current, later = later, later + current
def primes():
- deviders = {}
+ dividers = {}
x = 2
while True:
- if x not in deviders:
+ if x not in dividers:
yield x
- deviders[x*x] = [x]
+ dividers[x*x] = [x]
else:
- for d in deviders[x]:
- deviders.setdefault(d + x, []).append(d)
- del deviders[x]
+ for d in dividers[x]:
+ dividers.setdefault(d + x, []).append(d)
+ del dividers[x]
x += 1
def alphabet(**kwargs):
if 'letters' in kwargs:
letters = kwargs['letters']
elif 'code' in kwargs:
if kwargs['code'] is 'bg':
letters = 'абвгдежзийклмнопрстуфхцчшщъьюя'
elif kwargs['code'] is 'lat':
letters = 'abcdefghijklmnopqrstuvwxyz'
for letter in letters:
yield letter
def intertwined_sequences(sequences, generator_definitions=None):
generators = {}
for s in sequences:
sequence = s.pop('sequence')
length = s.pop('length')
if sequence not in generators.keys():
if sequence in globals():
generators[sequence] = globals()[sequence](**s)
else:
generators[sequence] = generator_definitions[sequence](**s)
for _ in range(length):
yield next(generators[sequence])