Теодор обнови решението на 18.03.2015 22:59 (преди над 9 години)
+from functools import reduce
+
+
+def extract_type(input_list, needed_type):
+ result = filter(lambda x: type(x[0]) == needed_type, input_list)
+ result = map(lambda x: str(x[0]) * x[1], result)
+ return reduce(lambda x, y: x + y, result)
+
+
+def reversed_dict(input_dict):
+ return dict(map(lambda x: (input_dict[x], x), input_dict))
+
+
+def flatten_dict(input_dict, prefix=""):
+ result = {}
+ for key in input_dict:
+ elem = input_dict[key]
+ if type(elem) is dict:
+ result.update(flatten_dict(elem, prefix + key + "."))
+ else:
+ result[prefix + key] = elem
+ return result
+
+
+def insert_deep(target_dict, key, item):
+ keys = key.split('.', 1)
+ if len(keys) == 1:
+ target_dict[key] = item
+ return
+ if keys[0] not in target_dict:
+ target_dict[keys[0]] = {}
+ insert_deep(target_dict[keys[0]], keys[1], item)
+
+
+def unflatten_dict(input_dict):
+ result = {}
+ for item in input_dict.items():
+ insert_deep(result, item[0], item[1])
+ return result
+
+
+def reps(elements):
+ return tuple(filter(lambda x: elements.count(x) > 1, elements))
Помисли кога extract_type
може да се счупи.