Георги обнови решението на 23.03.2015 16:29 (преди над 9 години)
+def extract_type(archived_text, filter_type):
+ filtered_text = ''
+
+ for (letter, repeats) in archived_text:
+ if type(letter) == filter_type:
+ filtered_text += repeats * str(letter)
+
+ return filtered_text
+
+
+def reversed_dict(dictionary):
+ result_dictionary = {}
+
+ for key in dictionary:
+ value = dictionary[key]
+
+ if value not in result_dictionary:
+ result_dictionary[value] = key
+
+ return result_dictionary
+
+
+def flatten_dict(dictionary, parent_key=''):
+ flatten_dictionary = {}
+ delimiter = '.'
+
+ for key, value in dictionary.items():
+ if not type(value) == dict:
+ flatten_dictionary[parent_key + key] = value
+ else:
+ extended_parent_key = parent_key + key + delimiter
+ flatten_dictionary.update(flatten_dict(value, extended_parent_key))
+
+ return flatten_dictionary
+
+
+def unflatten_dict(dictionary, unflatten_dictionary={}):
+ delimiter = '.'
+
+ for key, value in dictionary.items():
+ if delimiter not in key:
+ unflatten_dictionary[key] = value
+ else:
+ key, rest_of_the_key = key.split(delimiter, 1)
+
+ if key not in unflatten_dictionary:
+ unflatten_dictionary[key] = {}
+
+ unflatten_dict({rest_of_the_key: value}, unflatten_dictionary[key])
+ return unflatten_dictionary
+
+
+def reps(numbers):
+ result = ()
+
+ for number in numbers:
+ if numbers.count(number) > 1:
+ result += (number, )
+
+ return result