Йоан обнови решението на 22.03.2015 23:13 (преди над 9 години)
+def extract_type(list, filter_type):
+ return ''.join([str(element) * count for element, count
+ in list if type(element) is filter_type])
+
+
+def reversed_dict(dict):
+ return {value: key for (key, value) in dict.items()}
+
+
+def flatten_dict(unflatten):
+ def items():
+ for key, value in unflatten.items():
+ if isinstance(value, dict):
+ for subkey, subvalue in flatten_dict(value).items():
+ yield key + "." + subkey, subvalue
+ else:
+ yield key, value
+
+ return dict(items())
+
+
+def unflatten_dict(flatten):
+ result_dict = dict()
+ for key, value in flatten.items():
+ subkeys = key.split(".")
+ current_dict = result_dict
+ for subkey in subkeys[:-1]:
+ if subkey not in current_dict:
+ current_dict[subkey] = dict()
+ current_dict = current_dict[subkey]
+ current_dict[subkeys[-1]] = value
+
+ return result_dict
+
+
+def reps(list):
+ return tuple(x for x in list if list.count(x) != 1)