Слави обнови решението на 23.03.2015 16:31 (преди над 9 години)
+def extract_type(objects, object_type):
+ return "".join([
+ str(elements[0]) * elements[1] for elements in objects
+ if type(elements[0]) is object_type])
+
+
+def reversed_dict(dictionary):
+ return {key: value for key in dictionary.values()
+ for value in dictionary.keys() if key == dictionary[value]}
+
+
+def reps(items):
+ return tuple([element for element in list(items)
+ if items.count(element) != 1])
+
+
+def check_value(key, value_dictionary):
+ return {key + '.' + element: value_dictionary[element]
+ for element in value_dictionary.keys()}
+
+
+def flatten_dict(dictionary):
+ if all(type(value) is not dict for value in dictionary.values()):
+ return dictionary
+ else:
+ result = {}
+ for element, value in dictionary.items():
+ if type(value) is not dict:
+ result[element] = value
+ else:
+ for item in check_value(element, value).items():
+ result[item[0]] = item[1]
+ return flatten_dict(result)