Антонио обнови решението на 23.03.2015 15:03 (преди над 9 години)
+def extract_type(symbols, choice):
+ expression = ''
+ for symbol, num_of_symbols in symbols:
+ if type(symbol) is choice:
+ expression = expression + str(symbol) * num_of_symbols
+ return expression
+
+
+def reversed_dict(examples):
+ tmp = {}
+ for example in examples:
+ key = examples[example]
+ if key not in tmp:
+ tmp[key] = example
+ return tmp
+
+
+def flatten_dict(examples, lkey=''):
+ tmp = {}
+ for rkey, value in examples.items():
+ key = lkey + rkey
+ if type(value) == type(examples):
+ tmp.update(flatten_dict(value, key + '.'))
+ else:
+ tmp[key] = value
+ return tmp
+
+
+def unflatten_dict(examples):
+ result = {}
+ for key, value in examples.items():
+ partitions = key.split(".")
+ temporary = result
+ for portion in partitions[:-1]:
+ if portion not in temporary:
+ temporary[portion] = {}
+ temporary = temporary[portion]
+ temporary[partitions[-1]] = value
+ return result
+
+
+def reps(row):
+ sentence = [x for x in row if row.count(x) > 1]
+ return tuple(sentence)