Явор обнови решението на 19.03.2015 03:01 (преди над 9 години)
+def extract_type(letters_and_counts, str_type_name):
+ valid_pairs = [
+ pair for pair
+ in letters_and_counts
+ if isinstance(pair[0], str_type_name)]
+
+ return ''.join([
+ pair[1] * str(pair[0]) for pair
+ in valid_pairs
+ ])
+
+
+def reversed_dict(dict_fo_revers):
+ return(dict(zip(dict_fo_revers.values(), dict_fo_revers.keys())))
+
+
+def reps(list_of_numbers):
+ return(tuple([
+ number for number
+ in list_of_numbers
+ if list_of_numbers.count(number) > 1]))
+
+
+def flatten_dict(example_dict, left_key=''):
+ result_dict = {}
+
+ for rigth_key, value in example_dict.items():
+ key = left_key + rigth_key
+ if isinstance(value, dict):
+ result_dict.update(flatten_dict(value, key + '.'))
+ else:
+ result_dict[key] = value
+ return result_dict
+
+
+def unflatten_dict(example_dict):
+ flatten_dict = {}
+
+ for key, value in example_dict.items():
+ context = flatten_dict
+
+ 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(flatten_dict)