Решение на Пет малки функции от Георги Димов

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

Към профила на Георги Димов

Резултати

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

Код

def extract_type(archived_text, filter_type):
filtered_text = ''
for (letter, repeats) in archived_text:
if type(letter) == filter_type:
filtered_text += repeats * str(letter)
return filtered_text
def reversed_dict(dictionary):
result_dictionary = {}
for key in dictionary:
value = dictionary[key]
if value not in result_dictionary:
result_dictionary[value] = key
return result_dictionary
def flatten_dict(dictionary, parent_key=''):
flatten_dictionary = {}
delimiter = '.'
for key, value in dictionary.items():
if not type(value) == dict:
flatten_dictionary[parent_key + key] = value
else:
extended_parent_key = parent_key + key + delimiter
flatten_dictionary.update(flatten_dict(value, extended_parent_key))
return flatten_dictionary
def unflatten_dict(dictionary, unflatten_dictionary={}):
delimiter = '.'
for key, value in dictionary.items():
if delimiter not in key:
unflatten_dictionary[key] = value
else:
key, rest_of_the_key = key.split(delimiter, 1)
if key not in unflatten_dictionary:
unflatten_dictionary[key] = {}
unflatten_dict({rest_of_the_key: value}, unflatten_dictionary[key])
return unflatten_dictionary
def reps(numbers):
result = ()
for number in numbers:
if numbers.count(number) > 1:
result += (number, )
return result

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.166s

OK

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

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

+def extract_type(archived_text, filter_type):
+ filtered_text = ''
+
+ for (letter, repeats) in archived_text:
+ if type(letter) == filter_type:
+ filtered_text += repeats * str(letter)
+
+ return filtered_text
+
+
+def reversed_dict(dictionary):
+ result_dictionary = {}
+
+ for key in dictionary:
+ value = dictionary[key]
+
+ if value not in result_dictionary:
+ result_dictionary[value] = key
+
+ return result_dictionary
+
+
+def flatten_dict(dictionary, parent_key=''):
+ flatten_dictionary = {}
+ delimiter = '.'
+
+ for key, value in dictionary.items():
+ if not type(value) == dict:
+ flatten_dictionary[parent_key + key] = value
+ else:
+ extended_parent_key = parent_key + key + delimiter
+ flatten_dictionary.update(flatten_dict(value, extended_parent_key))
+
+ return flatten_dictionary
+
+
+def unflatten_dict(dictionary, unflatten_dictionary={}):
+ delimiter = '.'
+
+ for key, value in dictionary.items():
+ if delimiter not in key:
+ unflatten_dictionary[key] = value
+ else:
+ key, rest_of_the_key = key.split(delimiter, 1)
+
+ if key not in unflatten_dictionary:
+ unflatten_dictionary[key] = {}
+
+ unflatten_dict({rest_of_the_key: value}, unflatten_dictionary[key])
+ return unflatten_dictionary
+
+
+def reps(numbers):
+ result = ()
+
+ for number in numbers:
+ if numbers.count(number) > 1:
+ result += (number, )
+
+ return result

Георги обнови решението на 23.03.2015 16:55 (преди над 9 години)

def extract_type(archived_text, filter_type):
filtered_text = ''
for (letter, repeats) in archived_text:
if type(letter) == filter_type:
filtered_text += repeats * str(letter)
return filtered_text
def reversed_dict(dictionary):
result_dictionary = {}
for key in dictionary:
value = dictionary[key]
if value not in result_dictionary:
result_dictionary[value] = key
return result_dictionary
def flatten_dict(dictionary, parent_key=''):
flatten_dictionary = {}
delimiter = '.'
for key, value in dictionary.items():
if not type(value) == dict:
flatten_dictionary[parent_key + key] = value
else:
extended_parent_key = parent_key + key + delimiter
flatten_dictionary.update(flatten_dict(value, extended_parent_key))
return flatten_dictionary
-def unflatten_dict(dictionary, unflatten_dictionary={}):
+def unflatten_dict(dictionary):
delimiter = '.'
-
+ unflatten_dictionary = {}
for key, value in dictionary.items():
if delimiter not in key:
unflatten_dictionary[key] = value
else:
key, rest_of_the_key = key.split(delimiter, 1)
-
- if key not in unflatten_dictionary:
- unflatten_dictionary[key] = {}
-
- unflatten_dict({rest_of_the_key: value}, unflatten_dictionary[key])
+ unflatten_dictionary[key] = unflatten_dict({rest_of_the_key: value})
return unflatten_dictionary
def reps(numbers):
result = ()
for number in numbers:
if numbers.count(number) > 1:
result += (number, )
return result

Георги обнови решението на 23.03.2015 16:57 (преди над 9 години)

def extract_type(archived_text, filter_type):
filtered_text = ''
for (letter, repeats) in archived_text:
if type(letter) == filter_type:
filtered_text += repeats * str(letter)
return filtered_text
def reversed_dict(dictionary):
result_dictionary = {}
for key in dictionary:
value = dictionary[key]
if value not in result_dictionary:
result_dictionary[value] = key
return result_dictionary
def flatten_dict(dictionary, parent_key=''):
flatten_dictionary = {}
delimiter = '.'
for key, value in dictionary.items():
if not type(value) == dict:
flatten_dictionary[parent_key + key] = value
else:
extended_parent_key = parent_key + key + delimiter
flatten_dictionary.update(flatten_dict(value, extended_parent_key))
return flatten_dictionary
-def unflatten_dict(dictionary):
+def unflatten_dict(dictionary, unflatten_dictionary={}):
delimiter = '.'
- unflatten_dictionary = {}
+
for key, value in dictionary.items():
if delimiter not in key:
unflatten_dictionary[key] = value
else:
key, rest_of_the_key = key.split(delimiter, 1)
- unflatten_dictionary[key] = unflatten_dict({rest_of_the_key: value})
+
+ if key not in unflatten_dictionary:
+ unflatten_dictionary[key] = {}
+
+ unflatten_dict({rest_of_the_key: value}, unflatten_dictionary[key])
return unflatten_dictionary
def reps(numbers):
result = ()
for number in numbers:
if numbers.count(number) > 1:
result += (number, )
return result