Галин обнови решението на 22.03.2015 13:23 (преди над 9 години)
+def extract_type(elements, typeof):
+ result = ""
+ for element in elements:
+ if type(element[0]) == typeof:
+ result += str(element[0])*element[1]
+ return result
+
+
+def reversed_dict(dictionary):
+ new_dict = {}
+ for key in dictionary:
+ new_dict[dictionary[key]] = key
+ return new_dict
+
+
+def flatten_dict(dictionary, lkey=''):
+ result = {}
+ for key, val in dictionary.items():
+ key = lkey + key
+ if type(val) == dict:
+ result.update(flatten_dict(val, key+'.'))
+ else:
+ result[key] = val
+ return result
+
+
+def unflatten_dict(dictionary):
+ result = dict()
+ for key, value in dictionary.items():
+ parts = key.split(".")
+ diction = result
+ for part in parts[:-1]:
+ if part not in diction:
+ diction[part] = dict()
+ diction = diction[part]
+ diction[parts[-1]] = value
+ return result
+
+
+def reps(list):
+ return tuple(filter(lambda x: x in list[list.index(x)+1:], list))