Божидар обнови решението на 23.03.2015 11:19 (преди над 9 години)
+def unflatten(dictionary):
+ resultDict = dict()
+ for key, value in dictionary.items():
+ parts = key.split(".")
+ d = resultDict
+ for part in parts[:-1]:
+ if part not in d:
+ d[part] = dict()
+ d = d[part]
+ d[parts[-1]] = value
+ return resultDict
+
+
+def extract_type(collection, typ):
+ return (''.join([str(elem[0]) * elem[1]
+ for elem in collection if type(elem[0]) is typ]))
+
+
+def reversed_dict(collection):
+ return {collection[key]: key for key in collection}
+
+
+def reps(collection):
+ return (tuple(filter(lambda x: collection.count(x) > 1, collection)))
+
+
+def flatten_dict(collection, prefix=''):
+ return {prefix + '.' + k if prefix else k: v
+ for kk, vv in collection.items()
+ for k, v in flatten_dict(vv, kk).items()
+ } if isinstance(collection, dict) else {prefix: collection}