Виктор обнови решението на 23.03.2015 16:43 (преди над 9 години)
+def append_item(tuple, type):
+ result = ''
+ if isinstance(tuple[0], type):
+ for i in range(0, tuple[1]):
+ result += str(tuple[0])
+ return result
+
+
+def extract_type(list, type):
+ result = ''
+ for tuple in list:
+ result += append_item(tuple, type)
+ return result
+
+
+def reversed_dict(d):
+ new_dict = {}
+ for key in d:
+ new_dict[d[key]] = key
+ return new_dict
+
+
+def flatten_key(key, value):
+ if isinstance(value, dict):
+ return [(key + '.' + k, v) for k, v in flatten_dict(value).items()]
+ else:
+ return [(key, value)]
+
+
+def flatten_dict(d):
+ items = [item for k, v in d.items() for item in flatten_key(k, v)]
+ return dict(items)
+
+
+def append_key(keys, value, help_dict):
+ for key in keys[:-1]:
+ if key not in help_dict:
+ help_dict[key] = {}
+ help_dict = help_dict[key]
+ help_dict[keys[-1]] = value
+
+
+def unflatten_dict(d):
+ new_dict = {}
+ for key, value in d.items():
+ help_dict = new_dict
+ keys = key.split('.')
+ append_key(keys, value, help_dict)
+ return new_dict
+
+
+def reps(arr):
+ result = []
+ for item in arr:
+ if arr.count(item) > 1:
+ result.append(item)
+ return tuple(result)