Цвета обнови решението на 19.03.2015 09:19 (преди над 9 години)
+def extract_type(txt, txt_type):
+ return "".join([(str(x[0]) * x[1]) for x in txt if type(x[0]) == txt_type])
+
+
+def reversed_dict(dictionary):
+ return {dictionary[key]: key for key in dictionary}
+
+
+def flatten_dict(dictionary, p_key='', sep='.'):
+ result = []
+
+ for k, v in dictionary.items():
+ key = p_key + sep + k if p_key else k
+ if type(v) is dict:
+ result.extend(flatten_dict(v, key, sep=sep).items())
+ else:
+ result.append((key, v))
+
+ return dict(result)
+
+
+def unflatten_dict(dictionary):
+ result = dict()
+
+ for key, value in dictionary.items():
+ key_parts = key.split(".")
+ new_dict = result
+
+ for k in key_parts[:-1]:
+ if k not in new_dict:
+ new_dict[k] = dict()
+ new_dict = new_dict[k]
+
+ new_dict[key_parts[-1]] = value
+
+ return result
+
+
+def reps(lst):
+ return tuple([x for x in lst if lst.count(x) > 1])