Мартин обнови решението на 21.03.2015 21:56 (преди над 9 години)
+def extract_type(data, data_type):
+ return ''.join([str(element[0])*element[1]
+ for element in data
+ if type(element[0]) is data_type])
+
+
+def reversed_dict(data):
+ result = dict()
+ for key, value in data.items():
+ result[value] = key
+ return result
+
+
+def flatten_dict(data):
+ result = dict()
+ for key in data:
+ if type(data[key]) is dict:
+ for current_key, value in flatten_dict(data[key]).items():
+ result.update({"{}.{}".format(key, current_key): value})
+ else:
+ result[key] = data[key]
+ return result
+
+
+def unflatten_dict(data):
+ result = dict()
+ for key, value in data.items():
+ splitted = key.split('.')
+ for sequence in splitted:
+ temp = result
+ for element in splitted[:-1]:
+ if element not in temp.keys():
+ temp[element] = dict()
+
+ temp = temp[element]
+ temp[splitted[-1]] = value
+ return result
+
+
+def reps(data):
+ return tuple([element for element in data if data.count(element) > 1])