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

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

Към профила на Светлин Василев

Резултати

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

Код

def extract_type(arch_txt, the_type):
product = ''
for element in arch_txt:
if the_type is type(element[0]):
helper = element[1]
while helper > 0:
helper -= 1
product += str(element[0])
return product
def reversed_dict(not_reversed):
reversed_one = dict((y, x) for x, y in not_reversed.items())
return reversed_one
def flatten_dict(unflatten_one):
chek = True
while chek is True:
copy = {}
chek = False
for key, value in unflatten_one.items():
if type(value) is dict:
chek = True
for x, y in value.items():
copy[key + '.' + x] = y
else:
copy[key] = value
unflatten_one = copy
return unflatten_one
def reps(all_elements):
filter_elements = list()
for el in all_elements:
if all_elements.count(el) > 1:
filter_elements.append(el)
return tuple(filter_elements)

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.161s

OK

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

Светлин обнови решението на 23.03.2015 00:26 (преди над 9 години)

+def extract_type(arch_txt, the_type):
+ product = ''
+ for element in arch_txt:
+ if the_type is type(element[0]):
+ helper = element[1]
+ while helper > 0:
+ helper -= 1
+ product += str(element[0])
+ return product
+
+
+def reversed_dict(not_reversed):
+ reversed_one = dict((y, x) for x, y in not_reversed.items())
+ return reversed_one
+
+
+def flatten_dict(unflatten_one):
+ chek = True
+ while chek is True:
+ copy = {}
+ chek = False
+ for key, value in unflatten_one.items():
+ if type(value) is dict:
+ chek = True
+ for x, y in value.items():
+ copy[key + '.' + x] = y
+ else:
+ copy[key] = value
+ unflatten_one = copy
+ return unflatten_one
+
+
+def reps(all_elements):
+ filter_elements = list()
+ for el in all_elements:
+ if all_elements.count(el) > 1:
+ filter_elements.append(el)
+ return tuple(filter_elements)