Елица обнови решението на 21.03.2015 00:04 (преди над 9 години)
+def extract_type(data_to_extract, type_of_elements):
+ return ''.join(list(map(lambda x: str(x[0]) * x[1], list(filter(
+ lambda x: type(x[0]) is type_of_elements, data_to_extract)))))
+
+
+def reversed_dict(not_reversed):
+ return dict(list(map(lambda x: (x[1], x[0]), not_reversed.items())))
+
+
+def flatten_dict(not_flat):
+ flat = dict()
+ for key in not_flat:
+ if type(not_flat[key]) is dict:
+ new_flat = flatten_dict(not_flat[key])
+ for new_flat_key in new_flat:
+ flat[key + '.' + new_flat_key] = new_flat[new_flat_key]
+ else:
+ flat[key] = not_flat[key]
+ return flat
+
+
+def unflatten_dict(flat):
+ not_flat = dict()
+ for key in flat:
+ new_keys = key.split(".")
+ level = not_flat
+ for new_key in new_keys[:-1]:
+ if new_key not in level:
+ level[new_key] = dict()
+ level = level[new_key]
+ level[new_keys[-1]] = flat[key]
+ return not_flat
+
+
+def reps(data):
+ return tuple(list(filter(lambda x: data.count(x) != 1, data)))