Гюлджан обнови решението на 18.03.2015 00:33 (преди над 9 години)
+def extract_type(d, t):
+ result = ''
+ for item in d:
+ if isinstance(item[0], t):
+ result += str(item[0]) * item[1]
+ return result
+
+
+def reversed_dict(d):
+ result = []
+ for k, v in d.items():
+ result.append((v, k))
+ return dict(result)
+
+
+def flatten_dict(d, parent_key=''):
+ result = []
+ for k, v in d.items():
+ if parent_key:
+ new_key = parent_key + '.' + k
+ else:
+ new_key = k
+ if isinstance(v, dict):
+ result.extend(flatten_dict(v, new_key).items())
+ else:
+ result.append((new_key, v))
+ return dict(result)
+
+
+def unflatten_dict(d):
+ result = {}
+ for k, v in d.items():
+ context = result
+ for sub_key in k.split('.')[:-1]:
+ if sub_key not in context:
+ context[sub_key] = {}
+ context = context[sub_key]
+ context[k.split('.')[-1]] = v
+ return result
+
+
+def reps(d):
+ result = []
+ for item in d:
+ index = d.index(item)
+ if (item in d[index + 1:-1] or
+ item in d[0:index] or
+ item == d[-1]):
+ result.append(item)
+ return tuple(result)