Марио обнови решението на 23.03.2015 15:00 (преди над 9 години)
+def extract_type(list, type):
+ list_of_types = [str(e[0]) * e[1] for e in list if isinstance(e[0], type)]
+ return str.join('', list_of_types)
+
+
+def reversed_dict(dictionary):
+ return dict([(value, key) for key, value in dictionary.items()])
+
+
+KEYS_SEPARATOR = '.'
+
+
+def flatten_dict(dictionary, parent_name=''):
+ flat_dictionary = []
+
+ for key, value in dictionary.items():
+ key_name = parent_name + KEYS_SEPARATOR + key if parent_name else key
+ if isinstance(value, dict):
+ flat_dictionary.extend(flatten_dict(value, key_name).items())
+ else:
+ flat_dictionary.append((key_name, value))
+
+ return dict(flat_dictionary)
+
+
+def unflatten_dict(dictionary):
+ unflat_dictionary = {}
+
+ for key, value in dictionary.items():
+ nested_dictionary = unflat_dictionary
+
+ parent_keys = key.split(KEYS_SEPARATOR)
+ for parent_key in parent_keys[:-1]:
+ nested_dictionary = nested_dictionary.setdefault(parent_key, {})
+
+ nested_dictionary[parent_keys[-1]] = value
+
+ return unflat_dictionary
+
+
+def reps(list):
+ return tuple([element for element in list if list.count(element) > 1])