Стоян обнови решението на 20.03.2015 01:29 (преди над 9 години)
+def reversed_dict(res_dict):
+ return {res_dict[i]: i for i in res_dict}
+
+
+def flatten_dict_helper(init, lkey=''):
+ result = {}
+ for rkey, val in init.items():
+ key = lkey+rkey
+ if isinstance(val, dict):
+ result.update(flatten_dict_helper(val, key+'.'))
+ else:
+ result[key] = val
+ return result
+
+
+def flatten_dict(dictionary):
+ return flatten_dict_helper(dictionary, "")
+
+
+def unflatten_dict(dictionary):
+ result = {}
+ for key in dictionary:
+ parts = key.split(".")
+ d = result
+ for part in parts[:-1]:
+ if part not in d:
+ d[part] = {}
+ d = d[part]
+ d[parts[-1]] = dictionary[key]
+ return result
+
+
+def reps(numbers):
+ return tuple([x for x in numbers if numbers.count(x) > 1])
+
+
+def to_str(text):
+ result = ""
+ for i in text:
+ result += str(i)
+ return result
+
+
+def extract_type(txt, tps):
+ size = range(0, len(txt))
+ result = [str(txt[i][0])*txt[i][1] for i in size if type(txt[i][0]) is tps]
+ return to_str(result)