Екатерина обнови решението на 19.03.2015 22:26 (преди над 9 години)
+def extract_type(lst, tp):
+ return ''.join([symbol * n for symbol, n in lst if isinstance(symbol, tp)])
+
+
+def reversed_dict(dct):
+ return {value: key for key, value in dct.items()}
+
+
+def flatten_dict(dct):
+ result = {}
+ for key, value in dct.items():
+ if isinstance(value, dict):
+ r = flatten_dict(value)
+ for k, v in r.items():
+ result['{}.{}'.format(key, k)] = v
+ else:
+ result[key] = value
+ return result
+
+
+def unflatten_dict(dct):
+ result = {}
+ for key, value in dct.items():
+ keys = key.split('.')
+ tmp_dict = result
+ for subkey in keys[:-1]:
+ if subkey not in tmp_dict:
+ tmp_dict[subkey] = {}
+ tmp_dict = tmp_dict[subkey]
+ tmp_dict[keys[-1]] = value
+ return result
+
+
+def reps(lst):
+ return tuple([item for item in lst if lst.count(item) > 1])
Тествай extract_type
с различни типове