София обнови решението на 23.03.2015 15:47 (преди около 10 години)
▸ Покажи разликите+def extract_type(archive, search_type):
+ right_elements = [element
+ for element in archive
+ if isinstance(element[0], search_type)]
+ return ''.join([str(element[0]) * element[1]
+ for element in right_elements])
+
+
+def reversed_dict(dictionary):
+ return {value: key for key, value in dictionary.items()}
+
+
+def flatten_dict(dictionary):
+ flattened_dictionary = {}
+ for key, value in dictionary.items():
+ if isinstance(value, dict):
+ value = flatten_dict(value)
+ for inner_key, inner_value in value.items():
+ flattened_dictionary['.'.join([key, inner_key])] = inner_value
+ else:
+ flattened_dictionary[key] = value
+ return flattened_dictionary
+
+
+def unflatten_dict(dictionary):
+ unflattened_dictionary = {}
+ groups = {}
+ for key, value in dictionary.items():
+ if '.' in key:
+ base_key, _, inner_keys = key.partition('.')
+ if base_key not in groups:
+ groups[base_key] = {}
+ groups[base_key][inner_keys] = value
+ else:
+ unflattened_dictionary[key] = value
+ for key, group in groups.items():
+ unflattened_dictionary[key] = unflatten_dict(group)
+
+ return unflattened_dictionary
+
+
+def reps(collection):
+ return tuple([item for item in collection if collection.count(item) > 1])