Решение на Пет малки функции от Константин Димитров

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

Към профила на Константин Димитров

Резултати

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

Код

def extract_type(archive, key):
return ''.join([str(item[0]) * item[1] for item in archive
if type(item[0]) is key])
def reversed_dict(dictionary):
return {value: key for key, value in dictionary.items()}
def flatten_dict(dictionary, prev_key=''):
new_dict = {}
for key, value in dictionary.items():
new_key = prev_key + key
if isinstance(value, dict):
new_dict.update(flatten_dict(value, new_key + '.'))
else:
new_dict[new_key] = value
return new_dict
def reps(iterable):
return tuple(item for item in iterable if iterable.count(item) > 1)

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.378s

OK

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

Константин обнови решението на 20.03.2015 15:00 (преди около 9 години)

+def extract_type(archive, key):
+ return ''.join([str(item[0]) * item[1] for item in archive
+ if type(item[0]) is key])
+
+
+def reversed_dict(dictionary):
+ return {value: key for key, value in dictionary.items()}
+
+
+def flatten_dict(dictionary, prev_key=''):
+ new_dict = {}
+ for key, value in dictionary.items():
+ new_key = prev_key + key
+ if isinstance(value, dict):
+ new_dict.update(flatten_dict(value, new_key + '.'))
+ else:
+ new_dict[new_key] = value
+ return new_dict
+
+
+def reps(iterable):
+ return tuple(item for item in iterable if iterable.count(item) > 1)