Павел обнови решението на 17.03.2015 13:53 (преди над 9 години)
+def extract_type(items, return_type):
+ extracted_val = ""
+ for k in items:
+ if isinstance(k[0], return_type):
+ extracted_val += str(k[0]) * k[1]
+ return extracted_val
+
+
+def reversed_dict(items):
+ reversed_dict = {}
+ for k in items:
+ reversed_dict[items[k]] = k
+ return reversed_dict
+
+
+def reps(items):
+ rep = []
+ for k in items:
+ if items.count(k) > 1:
+ rep.append(k)
+ return tuple(rep)
+
+
+def flatten_dict(items):
+ flat_dict = {}
+
+ def _flatten_dict(key, value):
+ if isinstance(value, dict):
+ for key_in_value in value:
+ _flatten_dict(key + "." + key_in_value, value[key_in_value])
+ else:
+ flat_dict[key] = value
+
+ for key, value in items.items():
+ _flatten_dict(key, value)
+ return flat_dict
До тук добре. Остава unflatten_dict
:)