Решение на Пет малки функции от Христо Петков
Резултати
- 10 точки от тестове
- 0 бонус точки
- 10 точки общо
- 19 успешни тест(а)
- 0 неуспешни тест(а)
Код
def extract_type(symbol_count, data_type):
return ''.join(list(map((lambda x: str(x[0]) * x[1]),
filter((lambda x: type(x[0]) == data_type),
symbol_count))))
def reversed_dict(dictionary):
return dict(map((lambda x: (dictionary[x], x)), dictionary))
def reps(elements):
return tuple(filter((lambda x: elements.count(x) > 1), elements))
def flatten_dict(dictionary):
return flatten(dictionary)
def unflatten_dict(dictionary):
unflattened = {}
for item in dictionary.items():
temp_dict = unflattened
keys = str(item[0]).split('.')
for key in keys[:-1]:
if temp_dict.get(key, False):
temp_dict = temp_dict[key]
else:
temp_dict.update({key: {}})
temp_dict = temp_dict[key]
temp_dict[keys[-1]] = item[1]
return unflattened
def flatten(dictionary, key='', current={}):
for i, j in dictionary.items():
temp_key = key + '.' + str(i) if key else str(i)
if isinstance(j, dict):
current.update(flatten(j, key + '.' + i if key else i,
current))
else:
current[key + '.' + i if key else i] = j
return current