Георги обнови решението на 18.03.2015 02:00 (преди над 9 години)
+def extract_type(lst, given_type):
+ result = ""
+ for elem in lst:
+ if type(elem[0]) == given_type:
+ result += elem[0] * elem[1]
+ return result
+
+
+def reversed_dict(given_dict):
+ result = {}
+ for key in given_dict:
+ result[given_dict[key]] = key
+ return result
+
+
+def flatten_dict(given_dict):
+ separator = '.'
+ res = {}
+
+ def helper(dct, parent_keys=[]):
+ for key, value in dct.items():
+ if isinstance(value, dict):
+ helper(value, parent_keys + [key])
+ else:
+ sub_key = separator.join(parent_keys + [key])
+ res[sub_key] = value
+ helper(given_dict)
+ return res
+
+
+def unflatten_dict(given_dict):
+ res = {}
+ for key, value in given_dict.items():
+ context = res
+ for sub_key in key.split('.')[:-1]:
+ if sub_key not in context:
+ context[sub_key] = {}
+ context = context[sub_key]
+ context[key.split('.')[-1]] = value
+ return res
+
+
+def reps(lst):
+ result = []
+ for elem in lst:
+ if lst.count(elem) > 1:
+ result.append(elem)
+ return tuple(result)