Решение на Пет малки функции от Христо Владев

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

Към профила на Христо Владев

Резултати

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

Код

def extract_type(archive, type_filter):
return ''.join(
str(item) * reps for item, reps in archive if type(item) == type_filter
)
def reversed_dict(mapping):
return {value: key for key, value in mapping.items()}
def flatten_dict(mapping):
return dict(generate_flatten_dict(mapping))
def unflatten_dict(mapping):
return {}
def reps(items):
return tuple(item for item in items if items.count(item) > 1)
def generate_flatten_dict(mapping, separator='.'):
for key, value in mapping.items():
if type(value) == dict:
for subkey, subvalue in generate_flatten_dict(value):
yield key + separator + subkey, subvalue
else:
yield key, value

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.169s

OK

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

Христо обнови решението на 23.03.2015 15:56 (преди над 9 години)

+def extract_type(archive, type_filter):
+ return ''.join(
+ str(item) * reps for item, reps in archive if type(item) == type_filter
+ )
+
+def reversed_dict(mapping):
+ return {value: key for key, value in mapping.items()}
+
+def reps(items):
+ return tuple(item for item in items if items.count(item) > 1)

Христо обнови решението на 23.03.2015 16:34 (преди над 9 години)

def extract_type(archive, type_filter):
return ''.join(
str(item) * reps for item, reps in archive if type(item) == type_filter
)
def reversed_dict(mapping):
return {value: key for key, value in mapping.items()}
+def flatten_dict(mapping):
+ return dict(generate_flatten_dict(mapping))
+
def reps(items):
return tuple(item for item in items if items.count(item) > 1)
+
+def generate_flatten_dict(mapping):
+ for key, value in mapping.items():
+ if type(value) == dict:
+ for subkey, subvalue in generate_flatten_dict(value):
+ yield key + '.' + subkey, subvalue
+ else:
+ yield key, value

Христо обнови решението на 23.03.2015 16:36 (преди над 9 години)

def extract_type(archive, type_filter):
return ''.join(
str(item) * reps for item, reps in archive if type(item) == type_filter
)
def reversed_dict(mapping):
return {value: key for key, value in mapping.items()}
def flatten_dict(mapping):
return dict(generate_flatten_dict(mapping))
def reps(items):
return tuple(item for item in items if items.count(item) > 1)
-def generate_flatten_dict(mapping):
+def generate_flatten_dict(mapping, separator='.'):
for key, value in mapping.items():
if type(value) == dict:
for subkey, subvalue in generate_flatten_dict(value):
- yield key + '.' + subkey, subvalue
+ yield key + separator + subkey, subvalue
else:
yield key, value

Христо обнови решението на 23.03.2015 16:54 (преди над 9 години)

def extract_type(archive, type_filter):
return ''.join(
str(item) * reps for item, reps in archive if type(item) == type_filter
)
def reversed_dict(mapping):
return {value: key for key, value in mapping.items()}
def flatten_dict(mapping):
return dict(generate_flatten_dict(mapping))
+def unflatten_dict(mapping):
+ return {}
+
def reps(items):
return tuple(item for item in items if items.count(item) > 1)
def generate_flatten_dict(mapping, separator='.'):
for key, value in mapping.items():
if type(value) == dict:
for subkey, subvalue in generate_flatten_dict(value):
yield key + separator + subkey, subvalue
else:
yield key, value