Добромир обнови решението на 19.03.2015 22:20 (преди над 9 години)
+def extract_type(syms, srched_t):
+ return ''.join([str(p[0]) * p[1] for p in syms if type(p[0]) is srched_t])
+
+
+def reversed_dict(dikt):
+ return {v:k for k, v in dikt.items()}
+
+
+def flatten_dict(dikt, key=None):
+ flattened = {}
+ for top_k, top_v in dikt.items():
+ if type(top_v) is dict:
+ inner_dict = flatten_dict(top_v, top_k)
+ for inner_k, inner_v in inner_dict.items():
+ flattened[top_k + "." + inner_k] = inner_v
+ else:
+ flattened[top_k] = top_v
+ return flattened
+
+
+def unflatten_dict(dikt):
+ unflattened = {}
+ for top_k, top_v in dikt.items():
+ keys = top_k.split('.')
+ lst = unflattened
+ for inner_k in keys:
+ if inner_k not in lst.keys():
+ lst[inner_k] = {}
+ if inner_k == keys[-1]:
+ lst[inner_k] = top_v
+ lst = lst[inner_k]
+ return unflattened
+
+
+def reps(collection):
+ return tuple([x for x in collection if collection.count(x) != 1])
Имената ти са доста добре криптирани. Почти съм убедена, че разгадах част от тях. srched_t
е searched_type
, нали? :)