Решение на Пет малки функции от Мариян Игнатов

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

Към профила на Мариян Игнатов

Резултати

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

Код

def extract_type(symbols_and_repeats, chosen_type):
filtered_symbols = list(filter((lambda x: type(x[0]) is chosen_type),
symbols_and_repeats))
result = ''
for symbols, repeats in filtered_symbols:
for i in range(repeats):
result += str(symbols)
return result
def reversed_dict(dictionary):
countries_and_cities = dictionary.items()
result = {}
for country, city in countries_and_cities:
if city not in result:
result[city] = country
return result
def check_dictionary(old_key, item_for_check):
new_keys_and_values = []
for key, value in item_for_check.items():
if type(value) is not dict:
new_keys_and_values.append((old_key + '.' + key, value))
else:
for x in check_dictionary((old_key + '.' + key), value):
new_keys_and_values.append(x)
return new_keys_and_values
def flatten_dict(d):
result = {}
new_keys_and_values = []
for key, value in d.items():
if type(value) is not dict:
result[key] = value
else:
new_keys_and_values = check_dictionary(key, value)
for k, v in new_keys_and_values:
result[k] = v
new_keys_and_values = []
return result
def reps(elements):
return tuple([x for x in elements if elements.count(x) > 1])
def unflatten_dict(dictionary):
result = {}
for key, value in dictionary.items():
context = result
for k in key.split('.')[:-1]:
if k not in context:
context[k] = {}
context = context[k]
context[key.split('.')[-1]] = value
return result

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.184s

OK

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

Мариян обнови решението на 20.03.2015 23:47 (преди над 9 години)

+def extract_type(symbols_and_repeats, chosen_type):
+ filtered_symbols = list(filter((lambda x: type(x[0]) is chosen_type),
+ symbols_and_repeats))
+ result = ''
+ for symbols, repeats in filtered_symbols:
+ for i in range(repeats):
+ result += symbols
+ return result
+
+
+def reversed_dict(dictionary):
+ countries_and_cities = dictionary.items()
+ result = {}
+ for country, city in countries_and_cities:
+ if city not in result:
+ result[city] = country
+ return result
+
+
+def check_dictionary(old_key, item_for_check):
+ new_keys_and_values = []
+ for key, value in item_for_check.items():
+ if type(value) is not dict:
+ new_keys_and_values.append((old_key + '.' + key, value))
+ else:
+ for x in check_dictionary((old_key + '.' + key), value):
+ new_keys_and_values.append(x)
+ return new_keys_and_values
+
+
+def flatten_dict(d):
+ result = {}
+ new_keys_and_values = []
+ for key, value in d.items():
+ if type(value) is not dict:
+ result[key] = value
+ else:
+ new_keys_and_values = check_dictionary(key, value)
+ for k, v in new_keys_and_values:
+ result[k] = v
+ new_keys_and_values = []
+ return result
+
+
+def reps(elements):
+ return [x for x in elements if elements.count(x) > 1]
+
+
+def unflatten_dict(dictionary):
+ result = {}
+ for key, value in dictionary.items():
+ context = result
+ for k in key.split('.')[:-1]:
+ if k not in context:
+ context[k] = {}
+ context = context[k]
+ context[key.split('.')[-1]] = value
+ return result

Мариян обнови решението на 20.03.2015 23:57 (преди над 9 години)

def extract_type(symbols_and_repeats, chosen_type):
filtered_symbols = list(filter((lambda x: type(x[0]) is chosen_type),
symbols_and_repeats))
result = ''
for symbols, repeats in filtered_symbols:
for i in range(repeats):
result += symbols
return result
def reversed_dict(dictionary):
countries_and_cities = dictionary.items()
result = {}
for country, city in countries_and_cities:
if city not in result:
result[city] = country
return result
def check_dictionary(old_key, item_for_check):
new_keys_and_values = []
for key, value in item_for_check.items():
if type(value) is not dict:
new_keys_and_values.append((old_key + '.' + key, value))
else:
for x in check_dictionary((old_key + '.' + key), value):
new_keys_and_values.append(x)
return new_keys_and_values
def flatten_dict(d):
result = {}
new_keys_and_values = []
for key, value in d.items():
if type(value) is not dict:
result[key] = value
else:
new_keys_and_values = check_dictionary(key, value)
for k, v in new_keys_and_values:
result[k] = v
new_keys_and_values = []
return result
def reps(elements):
- return [x for x in elements if elements.count(x) > 1]
+ return tuple([x for x in elements if elements.count(x) > 1])
def unflatten_dict(dictionary):
result = {}
for key, value in dictionary.items():
context = result
for k in key.split('.')[:-1]:
if k not in context:
context[k] = {}
context = context[k]
context[key.split('.')[-1]] = value
return result

Мариян обнови решението на 21.03.2015 10:35 (преди над 9 години)

def extract_type(symbols_and_repeats, chosen_type):
filtered_symbols = list(filter((lambda x: type(x[0]) is chosen_type),
symbols_and_repeats))
result = ''
for symbols, repeats in filtered_symbols:
for i in range(repeats):
- result += symbols
+ result += str(symbols)
return result
def reversed_dict(dictionary):
countries_and_cities = dictionary.items()
result = {}
for country, city in countries_and_cities:
if city not in result:
result[city] = country
return result
def check_dictionary(old_key, item_for_check):
new_keys_and_values = []
for key, value in item_for_check.items():
if type(value) is not dict:
new_keys_and_values.append((old_key + '.' + key, value))
else:
for x in check_dictionary((old_key + '.' + key), value):
new_keys_and_values.append(x)
return new_keys_and_values
def flatten_dict(d):
result = {}
new_keys_and_values = []
for key, value in d.items():
if type(value) is not dict:
result[key] = value
else:
new_keys_and_values = check_dictionary(key, value)
for k, v in new_keys_and_values:
result[k] = v
new_keys_and_values = []
return result
def reps(elements):
return tuple([x for x in elements if elements.count(x) > 1])
def unflatten_dict(dictionary):
result = {}
for key, value in dictionary.items():
context = result
for k in key.split('.')[:-1]:
if k not in context:
context[k] = {}
context = context[k]
context[key.split('.')[-1]] = value
return result