Кристиан обнови решението на 22.03.2015 22:18 (преди над 9 години)
+import collections
+
+
+def extract_type(archived, type_):
+ extracted = [str(val) * rep for val, rep in archived if type(val) is type_]
+ return "".join(extracted)
+
+
+def reversed_dict(dictionary):
+ return {value: key for key, value in dictionary.items()}
+
+
+def reps(collection):
+ counter = collections.Counter(collection)
+ return tuple([item for item in collection if counter[item] > 1])
+
+
+def flatten_dict(dictionary):
+ flattened = {}
+ for key, value in dictionary.items():
+ if type(value) is dict:
+ for k, v in value.items():
+ flattened[key + '.' + k] = v
+ else:
+ flattened[key] = value
+ if any(type(value) is dict for key, value in flattened.items()):
+ return flatten_dict(flattened)
+ else:
+ return flattened