Цветан обнови решението на 22.03.2015 17:38 (преди над 9 години)
+def reps(elements):
+ result = []
+
+ for element in elements:
+ if elements.count(element) > 1:
+ result.append(element)
+
+ return tuple(result)
+
+
+def extract_type(elements, seekedType):
+ result = ''
+
+ for element in elements:
+ if type(element[0]) == seekedType:
+ result += str(element[0]) * element[1]
+
+ return result
+
+
+def reversed_dict(elements):
+ result = {}
+
+ for key in elements:
+ result[elements[key]] = key
+
+ return result
+
+
+def flatten_dict_with_start_key(outher_key, elements):
+ result = {}
+
+ for key in elements:
+ if(not type(elements[key]) == dict):
+ result[outher_key + key] = elements[key]
+ else:
+ current_key = outher_key + key + '.'
+ flatten = flatten_dict_with_start_key(current_key, elements[key])
+ result.update(flatten)
+
+ return result
+
+
+def flatten_dict(elements):
+ return flatten_dict_with_start_key("", elements)
+
+
+def add_unflatten_dict(splited_key, result, value):
+ if len(splited_key) == 1:
+ result[splited_key[0]] = value
+ return
+
+ if not splited_key[0] in result:
+ result[splited_key[0]] = {}
+
+ add_unflatten_dict(splited_key[1:], result[splited_key[0]], value)
+
+
+def unflatten_dict(elements):
+ result = {}
+
+ for key in elements:
+ splited_key = key.split('.')
+ add_unflatten_dict(splited_key, result, elements[key])
+
+ return result