Марина обнови решението на 23.03.2015 02:20 (преди над 9 години)
+def extract_type(data, needed):
+ return "".join([str(el[0]) * el[1] for el in data if type(el[0]) is needed])
+
+
+def reversed_dict(data):
+ return {data[k]: k for k in data}
+
+
+def reps(data):
+ return tuple(x for x in data if data.count(x) > 1)
+
+
+def flatten_dict(data, key=''):
+ new = {}
+ for x in data:
+ new_key = key + '.' + x if key else x
+ if isinstance(data[x], dict):
+ new.update(flatten_dict(data[x], new_key))
+ else:
+ new[new_key] = data[x]
+ return new
+
+
+def unflatten_dict(data):
+ result = {}
+ for x in data:
+ keys = x.split(".")
+ new = result
+ for key in keys[:-1]:
+ if key not in new:
+ new[key] = {}
+ new = new[key]
+ new[keys[-1]] = data[x]
+ return result
+