Васил обнови решението на 20.03.2015 18:57 (преди над 9 години)
+def extract_type(couples, input_t):
+
+ result = str()
+ for couple in couples:
+ if type(couple[0]) is input_t:
+ result += couple[1] * str(couple[0])
+
+ return result
+
+
+def reversed_dict(input_d):
+
+ res = dict()
+ for key, value in input_d.items():
+ res[value] = key
+ return res
+
+
+def reps(elements):
+
+ return tuple([x for x in elements if elements.count(x) > 1])
+
+
+def flatten_dict(input_d, left=''):
+
+ res = dict()
+ for right, value in input_d.items():
+ res_key = left + right
+ if type(value) is dict:
+ res.update(flatten_dict(value, res_key + '.'))
+ #flat = flatten_dict(value, res_key + '.')
+ # for k in flat.keys():
+ # res[k] = flat[k]
+ else:
+ res[res_key] = value
+ return res
+
+
+def unflatten_dict(input_d):
+
+ returned = dict()
+ for key, value in input_d.items():
+ sub = returned
+ splited_keys = key.split('.')
+ for s_key in splited_keys[:-1]:
+ if s_key not in sub.keys():
+ sub[s_key] = dict()
+ sub = sub[s_key]
+ sub[splited_keys[-1]] = value
+
+ return returned