Калоян обнови решението на 20.03.2015 07:05 (преди над 9 години)
+def extract_type(array, type_of_object):
+ result = [''.join([str(tuple_object[0])] * tuple_object[1]) for
+ tuple_object
+ in array if isinstance(tuple_object[0], type_of_object)]
+ return ''.join(result)
+
+
+global_variable = {}
+
+
+def reversed_dict(dict_to_reverse):
+ global_variable.clear()
+ for key, value in dict_to_reverse.items():
+ global_variable[value] = key
+ return global_variable
+
+
+def recursive_helper_flatten(dictinary, level):
+ new_level = ''
+ for key, value in dictinary.items():
+ if isinstance(value, dict) is False:
+ new_level = level+'.'+key
+ if new_level.startswith('.'):
+ new_level = new_level[1:]
+ global_variable[new_level] = value
+ else:
+ recursive_helper_flatten(value, level+'.'+key)
+
+
+def flatten_dict(dictinary):
+ global_variable.clear()
+ level = ''
+ recursive_helper_flatten(dictinary, level)
+ return global_variable
+
+
+def unflatten_dict(dictinary):
+ global_variable.clear()
+ for key, value in dictinary.items():
+ tmp_global = global_variable
+ count = 1
+ length_of_split = len(key.split('.'))
+ for splitted in key.split('.'):
+ if splitted not in tmp_global:
+ if count is length_of_split:
+ tmp_global[splitted] = value
+ else:
+ tmp_global[splitted] = {}
+ tmp_global = tmp_global[splitted]
+ count += 1
+ return global_variable
+
+
+def get_not_reapeating(values):
+ unique_elements = set(values)
+ new_unique_elements = list(unique_elements)
+ for value in values:
+ if values.count(value) > 1 and new_unique_elements.count(value) is 1:
+ new_unique_elements.remove(value)
+ return list(new_unique_elements)
+
+difference = lambda first_list, second_list: [x for x in first_list if x not
+ in second_list]
+
+
+def reps(variable):
+ return tuple(difference(variable, get_not_reapeating(variable)))