Виктория обнови решението на 22.03.2015 23:34 (преди над 9 години)
+def extract_type(args, type_of_args):
+ args = filter((lambda x: type(x[0]) == type_of_args), args)
+
+ result = str()
+ for arg in args:
+ result += arg[0]*arg[1]
+
+ return result
+
+
+def reversed_dict(to_be_reversed):
+ result = {}
+ for key, value in to_be_reversed.items():
+ result[value] = key
+
+ return result
+
+
+def reps(args):
+ return tuple(filter((lambda x: not args.count(x) == 1), args))
+
+
+def flatten_dict(to_be_flattened):
+ def simplify_dict(new_key, to_be_flattened, result):
+ for key, value in to_be_flattened.items():
+ if type(value) == dict and new_key == '':
+ simplify_dict(key, value, result)
+ elif type(value) == dict:
+ simplify_dict(new_key + '.' + key, value, result)
+ elif not new_key == '':
+ result[new_key + '.' + key] = value
+ else:
+ result[key] = value
+
+ return result
+
+ return simplify_dict('', to_be_flattened, {})
Тествай extract_type
с типове различни от str