Красимир обнови решението на 19.03.2015 21:53 (преди над 9 години)
+def extract_type(archive_text, search_type):
+ filter_ = lambda x: type(x[0]) is search_type
+ repeats = lambda x: str(x[0]) * x[1]
+ return ''.join(map(repeats, filter(filter_, archive_text)))
+
+
+def reversed_dict(items):
+ return {value: key for key, value in items.items()}
+
+
+def flatten_dict(items, left_key=''):
+ result = {}
+ for right_key, value in items.items():
+ key = left_key + right_key
+ if isinstance(value, dict):
+ result.update(flatten_dict(value, key + '.'))
+ else:
+ result[key] = value
+ return result
+
+
+def unflatten_dict(items):
+ result = {}
+ for key, value in items.items():
+ keys = key.split('.')
+ add_in_dept_dict(result, 0, keys, value)
+ return result
+
+
+def add_in_dept_dict(dict_, index, keys, value):
+ key = keys[index]
+ if index == len(keys) - 1:
+ dict_[key] = value
+ return dict_
+ if key not in dict_:
+ dict_[key] = {}
+ return add_in_dept_dict(dict_[key], index + 1, keys, value)
+
+
+def reps(items):
+ return tuple(item for item in items if items.count(item) > 1)