Милка обнови решението на 23.03.2015 13:31 (преди над 9 години)
+def extract_type(data, expected_type):
+ return "".join(list(map(lambda selected: str(selected[0]) * selected[1],
+ filter(lambda item: type(item[0]) is expected_type, data))))
+
+
+def reversed_dict(data):
+ return {value: key for key, value in data.items()}
+
+
+def reps(data):
+ return(tuple([item for item in data if data.count(item) > 1]))
+
+
+def flatten_dict(data, collected=''):
+ result = {}
+ for key, value in data.items():
+ container = collected + key
+ if type(value) is dict:
+ result.update(flatten_dict(value, container + '.'))
+ else:
+ result[container] = value
+ return result
+
+
+def generate_dict(data, unparsed_keys, value):
+ for key in unparsed_keys[:-1]:
+ data = data.setdefault(key, {})
+ data[unparsed_keys[-1]] = value
+
+
+def unflatten_dict(data):
+ result = {}
+ for key, value in data.items():
+ generate_dict(result, key.split('.'), value)
+ return result