Николай обнови решението на 22.03.2015 11:15 (преди над 9 години)
+from functools import reduce
+
+
+def extract_type(symbols, t):
+ return reduce(lambda first, second: first+str(second[0])*second[1],
+ filter(lambda item: type(item[0]) is t, symbols), '')
+
+
+def reversed_dict(d):
+ return {value: key for key, value in d.items()}
+
+
+def flatten_dict(d):
+ result = {}
+ for key, value in d.items():
+ if type(value) is not dict:
+ result[key] = value
+ else:
+ r = flatten_dict(value)
+ for k, v in r.items():
+ new_key = '{}.{}'.format(key, k)
+ result[new_key] = v
+ return result
+
+
+def unflatten_dict(d):
+ result = {}
+ for key, value in d.items():
+ context = result
+ new_keys = key.split('.')
+ for new_key in new_keys[:-1]:
+ if new_key not in context.keys():
+ context[new_key] = {}
+ context = context[new_key]
+ context[new_keys[-1]] = value
+ return result
+
+
+def reps(elements):
+ return tuple(filter(lambda elem: elements.count(elem) > 1, elements))