Тачо обнови решението на 21.03.2015 16:32 (преди над 9 години)
+def extract_type(mylist, mytype):
+ result = ""
+ for pair in mylist:
+ if type(pair[0]) is mytype:
+ result += str(pair[0]) * pair[1]
+ return result
+
+
+def reversed_dict(mydict):
+ return {value: key for key, value in mydict.items()}
+
+
+def flatten_dict(mydict):
+ result = {}
+ fragments = []
+
+ def helper_flatten(mydict, fragments):
+ for key, value in mydict.items():
+ if isinstance(value, dict):
+ helper_flatten(value, fragments + [key])
+ else:
+ newkey = '.'.join(fragments + [key])
+ result[newkey] = value
+ helper_flatten(mydict, fragments)
+ return result
+
+
+def unflatten_dict(mydict):
+ result = {}
+ for key, value in mydict.items():
+ fragments = key.split('.')
+ context = result
+ for fragment in fragments[:-1]:
+ if fragment not in context:
+ context[fragment] = {}
+ context = context[fragment]
+ context[fragments[-1]] = value
+ return result
+
+
+def reps(mylist):
+ return tuple([n for n in mylist if(mylist.count(n) > 1)])