Дарко обнови решението на 23.03.2015 12:59 (преди над 9 години)
+import collections
+
+
+def extract_type(some_text, type_of_symbols):
+ text = ''
+ for symbols in some_text:
+ if (type(symbols[0]) == type_of_symbols):
+ text = text + str(symbols[0]) * symbols[1]
+ return text
+
+
+def reversed_dict(original):
+ new_reversed = {v: k for k, v in original.items()}
+ return new_reversed
+
+
+def flatten_dict(d, parent_key='', sep='.'):
+ items = []
+ for k, v in d.items():
+ new_key = parent_key + sep + k if parent_key else k
+ if isinstance(v, collections.MutableMapping):
+ items.extend(flatten_dict(v, new_key, sep=sep).items())
+ else:
+ items.append((new_key, v))
+ return dict(items)
+
+
+def unflatten_dict(original):
+ result = dict()
+ for k, v in iter(original.items()):
+ parts = k.split(".")
+ d = result
+ for part in parts[:-1]:
+ if part not in d:
+ d[part] = dict()
+ d = d[part]
+ d[parts[-1]] = v
+ return result
+
+
+def reps(attribute):
+ duplicates = tuple([x for x in attribute if attribute.count(x) > 1])
+ return duplicates