Красимир обнови решението на 23.03.2015 16:33 (преди над 9 години)
+def extract_type(symbol_reps, t):
+ return ''.join([str(x[0]) * x[1] for x in symbol_reps if type(x[0]) is t])
+
+
+def reversed_dict(regular):
+ return {regular[k]: k for k in regular}
+
+
+def reps(l):
+ return tuple([x for i, x in enumerate(l) if x in l[:i] + l[i + 1:]])
+
+
+def flatten_dict(nested):
+ return flatten_dict_internal(nested)
+
+
+def flatten_dict_internal(unflatten, nested_key=''):
+ flatten = {}
+ for k, v in unflatten.items():
+ key = nested_key + k
+ if type(v) is dict:
+ flatten.update(flatten_dict_internal(v, key + '.'))
+ else:
+ flatten[key] = v
+
+ return flatten
+
+
+def unflatten_dict(flatten):
+ unflatten = {}
+ for k, v in flatten.items():
+ keys = k.split('.')
+ current = unflatten
+ for key in keys[:-1]:
+ if key not in current:
+ current[key] = {}
+ current = current[key]
+ current[keys[-1]] = v
+ return unflatten