Решение на Пет малки функции от Антонио Илиев

Обратно към всички решения

Към профила на Антонио Илиев

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 19 успешни тест(а)
  • 0 неуспешни тест(а)

Код

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)

Лог от изпълнението

...................
----------------------------------------------------------------------
Ran 19 tests in 0.152s

OK

История (1 версия и 0 коментара)

Антонио обнови решението на 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)