Янислав обнови решението на 23.03.2015 04:01 (преди над 9 години)
+from itertools import repeat
+
+
+def extract_type(data, extracting_type):
+ extracted_list = []
+ for element in data:
+ if type(element[0]) == extracting_type:
+ extracted_list.extend(repeat(element[0], element[1]))
+ return ''.join(map(str, extracted_list))
+
+
+def reversed_dict(data):
+ return dict(map(reversed, data.items()))
+
+
+# ...
+def flatten_dict(data, parent_key=''):
+ items, separator = [], '.'
+ for key, value in data.items():
+ new_key = parent_key + separator + key if parent_key else key
+ if isinstance(value, dict):
+ items.extend(flatten_dict(value, new_key).items())
+ else:
+ items.append((new_key, value))
+ return dict(items)
+
+
+# ...
+def unflatten_dict(data):
+ unflattened_dict = {}
+ for key, value in data.items():
+ keys = key.split(".")
+ value_dict = unflattened_dict
+ for new_key in keys[:-1]:
+ if new_key not in value_dict:
+ value_dict[new_key] = {}
+ value_dict = value_dict[new_key]
+ value_dict[keys[-1]] = value
+ return unflattened_dict
+
+
+def reps(data):
+ return tuple([element for element in data if data.count(element) != 1])