Решение на Генератори и итератори от Васил Малчев

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

Към профила на Васил Малчев

Резултати

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

Код

def fibonacci():
a, b = 0, 1
for num in count(1, 1):
a, b = b, a+b
yield a
def primes():
for num in count(2, 1):
for div in range(2, int(math.sqrt(num) + 1)):
if num % div == 0:
break;
if div == int(math.sqrt(num)):
yield num
def alphabet(code='', letters=''):
if code is not '' and letters :
letters = {'bg': [],
'lat':['a','b','c','d']
}
return iter(letters[code])
return iter(letters)

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

▸ Покажи лога

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

Васил обнови решението на 03.04.2015 16:57 (преди около 10 години)

▸ Покажи разликите
+def fibonacci():
+ a, b = 0, 1
+ for num in count(1, 1):
+ a, b = b, a+b
+ yield a
+
+
+def primes():
+ for num in count(2, 1):
+ for div in range(2, int(math.sqrt(num) + 1)):
+ if num % div == 0:
+ break;
+ if div == int(math.sqrt(num)):
+ yield num
+
+
+def alphabet(code='', letters=''):
+ if code is not '' and letters :
+ letters = {'bg': [],
+ 'lat':['a','b','c','d']
+ }
+ return iter(letters[code])
+ return iter(letters)