Христо обнови решението на 23.03.2015 15:47 (преди над 9 години)
+def extract_type(arg, type_arg):
+ string = ''
+ for element in arg:
+ if type(element[0]) == type_arg:
+ string += str(element[0]) * element[1]
+ return string
+
+
+def reversed_dict(dictionary):
+ return dict(zip(dictionary.values(), dictionary.keys()))
+
+
+def flatten_dict(dictionary):
+ flatt_dict = {}
+
+ def make_flatten_dict(dictionary):
+ for key, value in dictionary.items():
+ if type(value) is dict:
+ make_flatten_dict(dict([(key + '.' + k, v)
+ for k, v in value.items()]))
+ else:
+ flatt_dict.update({key: value})
+ return flatt_dict
+ return make_flatten_dict(dictionary)
+
+
+def unflatten_dict(dictionary):
+ unflatten_dictionary = {}
+ for key, value in dictionary.items():
+ split_keys = key.split(".")
+ temporary_dictionary = unflatten_dictionary
+ for element in split_keys[:-1]:
+ if element not in temporary_dictionary:
+ temporary_dictionary[element] = {}
+ temporary_dictionary = temporary_dictionary[element]
+ temporary_dictionary[split_keys[-1]] = value
+ return unflatten_dictionary
+
+
+def reps(items):
+ return tuple(filter(lambda x: items.count(x) >= 2, items))