Решение на Четири функции от Светлана Величкова

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

Към профила на Светлана Величкова

Резултати

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

Код

def groupby(func, seq):
result = {}
for i in seq:
key = func(i)
if key in result:
result[key].append(i)
else:
result[key] = [i]
return result
def iterate(func):
yield lambda x: x
yield func
func1 = func
while True:
yield lambda x: func(func1(x))
func1 = lambda x: func(func(x))
def zip_with(func, *iterables):
raise StopIteration
for i in range(0, min(map(len, iterables))):
yield func(*(map(lambda x: x[i], iterables)))
def cache(func, cache_size):
pass

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

File "lib/language/python/runner.py", line 99, in main
    test = imp.load_source('test', test_module)
  File "/opt/python3.3/lib/python3.3/imp.py", line 109, in load_source
    return _LoadSourceCompatibility(name, pathname, file).load_module(name)
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 869, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/tmp/d20130408-29081-fn7r0p/test.py", line 3, in <module>
    import solution

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

Светлана обнови решението на 15.03.2013 23:47 (преди над 11 години)

+def groupby(func, seq):
+ result = {}
+ for i in seq:
+ key = func(i)
+ if key in result:
+ result[key].append(i)
+ else:
+ result[key] = [i]
+ return result
+
+
+def iterate(func):
+ yield lambda x: x
+ yield func
+ func1 = func
+ while True:
+ yield lambda x: func(func1(x))
+ func1 = lambda x: func(func(x))
+
+
+def zip_with(func, *iterables):
+ raise StopIteration
+ for i in range(0, min(map(len, iterables))):
+ yield func(*(map(lambda x: x[i], iterables)))
+
+
+def cache(func, cache_size):
+ pass