Решение на Пет малки функции от Виктор Цонев

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

Към профила на Виктор Цонев

Резултати

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

Код

def extract_type(text, type_to_print):
to_return = ''
for i in text:
if type(i[0]) is type_to_print:
to_return += i[0]*i[1]
return to_return
def reversed_dict(dict_to_reverse):
dict_to_return = {}
for i in dict_to_reverse:
dict_to_return[dict_to_reverse[i]] = i
return dict_to_return
def reps(elements):
elements_to_return = []
for i in elements:
if elements.count(i) > 1:
elements_to_return.append(i)
return elements_to_return
def is_flatten(the_dict):
for i in the_dict:
if type(the_dict[i]) is dict:
return False
return True
def flatten_dict(the_dict):
while not is_flatten(the_dict):
help_dict = {}
for i in the_dict:
if type(the_dict[i]) is dict:
for k in the_dict[i]:
help_dict[str(i) + '.' + str(k)] = the_dict[i][k]
else:
help_dict[i] = the_dict[i]
the_dict = {}
for i in help_dict:
the_dict[i] = help_dict[i]
return the_dict

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.168s

OK

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

Виктор обнови решението на 23.03.2015 11:37 (преди около 9 години)

+def extract_type(text, type_to_print):
+ to_return = ''
+ for i in text:
+ if type(i[0]) is type_to_print:
+ to_return += i[0]*i[1]
+ return to_return
+
+
+def reversed_dict(dict_to_reverse):
+ dict_to_return = {}
+ for i in dict_to_reverse:
+ dict_to_return[dict_to_reverse[i]] = i
+ return dict_to_return
+
+
+def reps(elements):
+ elements_to_return = []
+ for i in elements:
+ if elements.count(i) > 1:
+ elements_to_return.append(i)
+ return elements_to_return

Виктор обнови решението на 23.03.2015 12:55 (преди около 9 години)

def extract_type(text, type_to_print):
to_return = ''
for i in text:
if type(i[0]) is type_to_print:
to_return += i[0]*i[1]
return to_return
def reversed_dict(dict_to_reverse):
dict_to_return = {}
for i in dict_to_reverse:
dict_to_return[dict_to_reverse[i]] = i
return dict_to_return
def reps(elements):
elements_to_return = []
for i in elements:
if elements.count(i) > 1:
elements_to_return.append(i)
return elements_to_return
+
+
+def is_flatten(the_dict):
+ for i in the_dict:
+ if type(the_dict[i]) is dict:
+ return False
+ return True
+
+
+def flatten_dict(the_dict):
+ while not is_flatten(the_dict):
+ help_dict = {}
+ for i in the_dict:
+ if type(the_dict[i]) is dict:
+ for k in the_dict[i]:
+ help_dict[str(i) + '.' + str(k)] = the_dict[i][k]
+ else:
+ help_dict[i] = the_dict[i]
+ the_dict = {}
+ for i in help_dict:
+ the_dict[i] = help_dict[i]
+ return the_dict