Емил обнови решението на 20.03.2015 15:29 (преди над 9 години)
+def repeat(symbol, num_of_reps):
+ result = ""
+ for i in range(num_of_reps):
+ result += str(symbol)
+ return result
+
+
+def extract_type(input_, type_):
+ result = ""
+ for element in input_:
+ if type(element[0]) is type_:
+ result += repeat(element[0], element[1])
+ return result
+
+
+def reversed_dict(input_):
+ result = {}
+ for key, value in input_.items():
+ result[value] = key
+ return result
+
+
+def flatten_dict(input_, main_key=""):
+ result = {}
+ for key, value in input_.items():
+ new_key = main_key + "." + key if main_key != "" else key
+ if type(value) is dict:
+ result.update(flatten_dict(value, new_key))
+ else:
+ result[new_key] = value
+ return result
+
+
+def unflatten_dict(dictionary):
+ result = {}
+ for key, value in dictionary.items():
+ key_parts = key.split(".")
+ new_dict = result
+ for part in key_parts[:-1]:
+ if part not in new_dict:
+ new_dict[part] = {}
+ new_dict = new_dict[part]
+ new_dict[key_parts[-1]] = value
+ return result
+
+
+def reps(arguments):
+ return tuple(x for x in arguments if arguments.count(x) > 1)