Михаел обнови решението на 23.03.2015 16:55 (преди над 9 години)
+from itertools import repeat
+
+
+def extract_type(paylaod, type_flag):
+ filtered = list(t for t in paylaod if type(t[0]) is type_flag)
+ extended = (list(repeat(obj, number)) for obj, number in filtered)
+ res = ''
+ for l in extended:
+ res += ''.join(l)
+ return res
+
+
+def reversed_dict(given_dict):
+ return dict(zip(given_dict.values(), given_dict.keys()))
+
+
+def flatten_dict(d):
+ return d
+
+
+def unflatten_dict(d):
+ return d
+#
+# def flatten_dict(nested):
+# pairs = []
+# for k, v in nested.items():
+# doted_key = get_doted_key(k, nested)
+# pairs.append((doted_key, parse_doted_key(nested, doted_key)))
+# return dict(pairs)
+
+
+# def get_doted_key(key, nested_dict):
+# val = nested_dict[key]
+# print('key: {}'.format(key))
+# print('nested_dict: {}'.format(nested_dict))
+# if type(val) is dict:
+# print('val: {}'.format(val))
+# print('next_key: {}'.format(val.keys()))
+# return '.'.join(key + get_doted_key(val.keys()[0], val))
+# else:
+# return key
+#
+#
+# def parse_doted_key(nested_dict, doted_key):
+# val = nested_dict
+# print('doted_key: {}'.format(doted_key))
+# for key in doted_key.split('.'):
+# val = val[key]
+# return val
+#
+
+def reps(collection):
+ uniques = []
+ for item in collection:
+ if item not in uniques:
+ uniques.append(item)
+ return type(collection)(uniques)