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

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

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

Резултати

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

Код

def extract_type(text, type_):
if type_ is str:
extracted_info = ''
else:
extracted_info = 0
for i in text:
if (type(i[0]) is type_):
j = 0
while (j < i[1]):
extracted_info = extracted_info + i[0]
j += 1
return extracted_info
def reversed_dict(dictionary):
new_dict = {v: k for k, v in dictionary.items()}
return new_dict
def reps(sequence):
new_sequence = list()
for i in sequence:
if(sequence.count(i) > 1):
new_sequence.append(i)
return tuple(new_sequence)
def flatten_dict(dictionary, level=''):
flatter_dict = {}
for k, v in dictionary.items():
if(v is dict):
flatter_dict.update(flatten_dict(v, level + k))
else:
flatter_dict['.'.join(level + k)] = v
return flatter_dict

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.169s

OK

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

Антон обнови решението на 23.03.2015 14:45 (преди над 9 години)

+def extract_type(text, type_):
+ if type_ is str:
+ extracted_info = ''
+ else:
+ extracted_info = 0
+ for i in text:
+ if (type(i[0]) is type_):
+ j = 0
+ while (j < i[1]):
+ extracted_info = extracted_info + i[0]
+ j += 1
+ return extracted_info
+
+
+def reversed_dict(dictionary):
+ new_dict = {v:k for k,v in dictionary.items()}
+ return new_dict
+
+
+def reps(sequence):
+ new_sequence = list()
+ for i in sequence:
+ if(sequence.count(i) > 1):
+ new_sequence.append(i)
+ return tuple(new_sequence)

Антон обнови решението на 23.03.2015 15:29 (преди над 9 години)

def extract_type(text, type_):
if type_ is str:
extracted_info = ''
else:
extracted_info = 0
for i in text:
if (type(i[0]) is type_):
j = 0
while (j < i[1]):
extracted_info = extracted_info + i[0]
j += 1
return extracted_info
def reversed_dict(dictionary):
new_dict = {v:k for k,v in dictionary.items()}
return new_dict
def reps(sequence):
new_sequence = list()
for i in sequence:
if(sequence.count(i) > 1):
new_sequence.append(i)
return tuple(new_sequence)
+
+
+def flatten_dict(dictionary, level = ''):
+ flatter_dict = {}
+ for k, v in dictionary.items():
+ if(v is dict):
+ flatter_dict.update(flatten_dict(v, level + k))
+ else:
+ flatter_dict['.'.join(level + k)] = v
+ return flatter_dict
+

Антон обнови решението на 23.03.2015 15:34 (преди над 9 години)

def extract_type(text, type_):
- if type_ is str:
- extracted_info = ''
- else:
- extracted_info = 0
- for i in text:
- if (type(i[0]) is type_):
- j = 0
- while (j < i[1]):
- extracted_info = extracted_info + i[0]
- j += 1
- return extracted_info
+ if type_ is str:
+ extracted_info = ''
+ else:
+ extracted_info = 0
+ for i in text:
+ if (type(i[0]) is type_):
+ j = 0
+ while (j < i[1]):
+ extracted_info = extracted_info + i[0]
+ j += 1
+ return extracted_info
def reversed_dict(dictionary):
- new_dict = {v:k for k,v in dictionary.items()}
- return new_dict
+ new_dict = {v: k for k, v in dictionary.items()}
+ return new_dict
def reps(sequence):
- new_sequence = list()
- for i in sequence:
- if(sequence.count(i) > 1):
- new_sequence.append(i)
- return tuple(new_sequence)
+ new_sequence = list()
+ for i in sequence:
+ if(sequence.count(i) > 1):
+ new_sequence.append(i)
+ return tuple(new_sequence)
-def flatten_dict(dictionary, level = ''):
- flatter_dict = {}
+def flatten_dict(dictionary, level=''):
- for k, v in dictionary.items():
+ flatter_dict = {}
- if(v is dict):
+ for k, v in dictionary.items():
- flatter_dict.update(flatten_dict(v, level + k))
+ if(v is dict):
- else:
+ flatter_dict.update(flatten_dict(v, level + k))
- flatter_dict['.'.join(level + k)] = v
+ else:
- return flatter_dict
+ flatter_dict['.'.join(level + k)] = v
-
+ return flatter_dict