Иван обнови решението на 22.03.2015 23:53 (преди над 9 години)
+def extract_type(input_data, needed_type):
+ result = ""
+ for current_element in input_data:
+ if type(current_element[0]) is needed_type:
+ for i in range(0, current_element[1]):
+ result += str(current_element[0])
+
+ return result
+
+
+def reversed_dict(input_data):
+ result = {}
+ for key, value in input_data.items():
+ if key in result:
+ pass
+ result[value] = key
+
+ return result
+
+
+def flatten_dict(input_data):
+ result = {}
+ for key, value in input_data.items():
+ if type(value) is dict:
+ for subkey, subvalue in flatten_dict(value).items():
+ new_key = key + "." + subkey
+ result[new_key] = subvalue
+ else:
+ result[key] = value
+ return result
+
+
+def unflatten_dict(input_data):
+ result = {}
+ for key, value in input_data.items():
+ subdict_keys = key.split(".")
+ temp_res = result
+ for el in subdict_keys[:-1]:
+ if el not in temp_res:
+ temp_res[el] = dict()
+ temp_res = temp_res[el]
+ temp_res[subdict_keys[-1]] = value
+ return result
+
+
+def reps(input_data):
+ result = []
+ for current_element in input_data:
+ if input_data.count(current_element) > 1:
+ result.append(current_element)
+
+ return tuple(result)