Елица обнови решението на 20.03.2015 00:34 (преди над 9 години)
+def reversed_dict(dictionary):
+ return dict(zip(dictionary.values(), dictionary.keys()))
+
+
+def extract_type(a_list, a_type):
+ return ''.join([x[0] * x[1] for x in a_list if isinstance(x[0], a_type)])
+
+
+def flatten_dict(dictionary):
+ def flatten(dictionary, key='', current={}):
+ for k, v in dictionary.items():
+ if isinstance(v, dict):
+ current.update(flatten(v, key + '.' + k if key else k,
+ current))
+ else:
+ current[key + '.' + k if key else k] = v
+ return current
+ return flatten(dictionary)
+
+
+def unflatten_dict(dictionary):
+ unflattened = {}
+ for item in dictionary.items():
+ temporary_dict = unflattened
+ keys = item[0].split('.')
+ for key in keys[:-1]:
+ if temporary_dict.get(key, False):
+ temporary_dict = temporary_dict[key]
+ else:
+ temporary_dict.update({key: {}})
+ temporary_dict = temporary_dict[key]
+ temporary_dict[keys[-1]] = item[1]
+ return unflattened
+
+
+def reps(a_list):
+ return tuple(elem for elem in a_list if a_list.count(elem) - 1)