Йордан обнови решението на 21.03.2015 19:55 (преди над 9 години)
+def extract_type(list_of_tuples, given_type):
+ result = ''
+ for item in list_of_tuples:
+ if type(item[0]) is given_type:
+ result = result + item[1]*str(item[0])
+ return result
+
+
+def reversed_dict(to_reverse):
+ return {value: key for key, value in to_reverse.items()}
+
+
+def flatten_dict(unflatten, current_key=''):
+ result = {}
+ for sub_key, value in unflatten.items():
+ if type(value) is dict:
+ result.update(flatten_dict(value, current_key+sub_key+'.'))
+ else:
+ result[current_key+sub_key] = value
+ return result
+
+
+def unflatten_dict(flatten):
+ result = {}
+ for key, value in flatten.items():
+ context = result
+ for sub_key in key.split(".")[:-1]:
+ if sub_key in context:
+ context = context[sub_key]
+ else:
+ context[sub_key] = dict()
+ context = context[sub_key]
+ context[key.split(".")[-1]] = value
+ return result
+
+
+def reps(elements):
+ return tuple([el for el in elements if(elements.count(el) > 1)])