Александър обнови решението на 18.03.2015 15:38 (преди над 9 години)
+def extract_type(symbols, wanted):
+ return ''.join(str(x)*y for x, y in symbols if type(x) == wanted)
+
+
+def reversed_dict(original):
+ return {original[key]: key for key in original}
+
+
+def flatten_dict(original, previous_key=None):
+ flattend = {}
+
+ for key, value in original.items():
+ if previous_key:
+ key = '.'.join([previous_key, key])
+
+ if isinstance(value, dict):
+ flattend.update(flatten_dict(value, key))
+
+ else:
+ flattend[key] = value
+
+ return flattend
+
+
+def unflatten_dict(original):
+ result = {}
+
+ for key, value in original.items():
+ parts = key.split('.')
+ unflattend = result
+
+ for part in parts[:-1]:
+ if part not in unflattend:
+ unflattend[part] = {}
+ unflattend = unflattend[part]
+
+ unflattend[parts[-1]] = value
+
+ return result
+
+
+def reps(elements):
+ return tuple(filter(lambda x: elements.count(x) > 1, elements))