Решение на Пет малки функции от Любослава Димитрова

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

Към профила на Любослава Димитрова

Резултати

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

Код

def extract_type(array, input_type):
result = ""
for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
def unflatten_dict(dictionary):
result = dict()
temporary = dictionary
for key in temporary:
if len(key) == 1:
if key in result:
internal = result[key]
for internal_key in temporary[key]:
internal[internal_key] = temporary[key][internal_key]
result[key] = internal
else:
result[key] = temporary[key]
else:
internal = dict()
if key[:-2] in result.keys():
internal = result[key[:-2]]
internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
else:
internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
return unflatten_dict(result)
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

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

...................
----------------------------------------------------------------------
Ran 19 tests in 0.135s

OK

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

Любослава обнови решението на 22.03.2015 19:54 (преди около 9 години)

+def extract_type(input_array, input_type):
+ result = ""
+ for item in input_array:
+ for symbol in item[:-1]:
+ if type(symbol) is input_type:
+ result = result + item[-1] * str(symbol)
+ return result
+
+
+def reversed_dict(dictionary):
+ result = dict()
+ values = []
+ for value in dictionary.values():
+ values.append(value)
+ unique = list(set(values))
+ for item in unique:
+ for key in dictionary:
+ if dictionary[key] == item:
+ result[item] = key
+ return result
+
+
+def reps(input):
+ result = []
+ for item in input:
+ if input.count(item) > 1:
+ result.append(item)
+ return tuple(result)

Любослава обнови решението на 23.03.2015 06:34 (преди около 9 години)

def extract_type(input_array, input_type):
result = ""
for item in input_array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
+def key_value_generator(dictionary):
+ result = []
+ temporary = dictionary
+ for key in dictionary:
+ if type(dictionary[key]) is not dict:
+ result.append((key, dictionary[key]))
+ else:
+ temporary = dictionary[key]
+ for item in key_value_generator(temporary):
+ result.append((key + "." + item[0], item[1]))
+ return result
+
+
+def flatten_dict(dictionary):
+ result = dict()
+ for pair in key_value_generator(dictionary):
+ result[pair[0]] = pair[1]
+ return result
+
+
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

Любослава обнови решението на 23.03.2015 14:57 (преди около 9 години)

def extract_type(input_array, input_type):
result = ""
for item in input_array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
+def unflatten_dict(test):
+ result = dict()
+ temporary = test
+ for key in temporary:
+ if len(key) == 1:
+ result[key] = temporary[key]
+ else:
+ internal_hash = dict()
+ if key[:-2] in result.keys():
+ internal_hash = result[key[:-2]]
+ internal_hash[str(key[-1])] = temporary[key]
+ result[key[:-2]] = internal_hash
+ else:
+ internal_hash[str(key[-1])] = temporary[key]
+ result[key[:-2]] = internal_hash
+ complex_keys = [key for key in result.keys() if len(key) > 1]
+ if len(complex_keys) == 0:
+ return result
+ else:
+ temporary = result
+ result = unflatten_dict(temporary)
+ return result
+
+
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

Любослава обнови решението на 23.03.2015 15:03 (преди около 9 години)

-def extract_type(input_array, input_type):
+def extract_type(array, input_type):
result = ""
- for item in input_array:
+ for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
def unflatten_dict(test):
result = dict()
temporary = test
for key in temporary:
if len(key) == 1:
result[key] = temporary[key]
else:
- internal_hash = dict()
+ internal = dict()
if key[:-2] in result.keys():
- internal_hash = result[key[:-2]]
- internal_hash[str(key[-1])] = temporary[key]
- result[key[:-2]] = internal_hash
+ internal = result[key[:-2]]
+ internal[str(key[-1])] = temporary[key]
+ result[key[:-2]] = internal
else:
- internal_hash[str(key[-1])] = temporary[key]
- result[key[:-2]] = internal_hash
+ internal[str(key[-1])] = temporary[key]
+ result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
temporary = result
result = unflatten_dict(temporary)
return result
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

Любослава обнови решението на 23.03.2015 15:05 (преди около 9 години)

def extract_type(array, input_type):
result = ""
for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
-def unflatten_dict(test):
+def unflatten_dict(dictionary):
result = dict()
- temporary = test
+ temporary = dictionary
for key in temporary:
if len(key) == 1:
result[key] = temporary[key]
else:
internal = dict()
if key[:-2] in result.keys():
internal = result[key[:-2]]
internal[str(key[-1])] = temporary[key]
result[key[:-2]] = internal
else:
internal[str(key[-1])] = temporary[key]
result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
temporary = result
result = unflatten_dict(temporary)
return result
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

Любослава обнови решението на 23.03.2015 16:05 (преди около 9 години)

def extract_type(array, input_type):
result = ""
for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
def unflatten_dict(dictionary):
result = dict()
temporary = dictionary
for key in temporary:
if len(key) == 1:
result[key] = temporary[key]
else:
internal = dict()
if key[:-2] in result.keys():
internal = result[key[:-2]]
internal[str(key[-1])] = temporary[key]
result[key[:-2]] = internal
else:
internal[str(key[-1])] = temporary[key]
result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
- temporary = result
- result = unflatten_dict(temporary)
- return result
+ return unflatten_dict(result)
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
- return tuple(result)
+ return tuple(result)

Любослава обнови решението на 23.03.2015 16:40 (преди около 9 години)

def extract_type(array, input_type):
result = ""
for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
def unflatten_dict(dictionary):
result = dict()
temporary = dictionary
for key in temporary:
if len(key) == 1:
result[key] = temporary[key]
else:
internal = dict()
if key[:-2] in result.keys():
internal = result[key[:-2]]
- internal[str(key[-1])] = temporary[key]
+ internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
else:
internal[str(key[-1])] = temporary[key]
result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
return unflatten_dict(result)
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

Любослава обнови решението на 23.03.2015 16:45 (преди около 9 години)

def extract_type(array, input_type):
result = ""
for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
def unflatten_dict(dictionary):
result = dict()
temporary = dictionary
for key in temporary:
if len(key) == 1:
result[key] = temporary[key]
else:
internal = dict()
if key[:-2] in result.keys():
internal = result[key[:-2]]
internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
else:
- internal[str(key[-1])] = temporary[key]
+ internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
return unflatten_dict(result)
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
return tuple(result)

Любослава обнови решението на 23.03.2015 16:56 (преди около 9 години)

def extract_type(array, input_type):
result = ""
for item in array:
for symbol in item[:-1]:
if type(symbol) is input_type:
result = result + item[-1] * str(symbol)
return result
def reversed_dict(dictionary):
result = dict()
values = []
for value in dictionary.values():
values.append(value)
unique = list(set(values))
for item in unique:
for key in dictionary:
if dictionary[key] == item:
result[item] = key
return result
def key_value_generator(dictionary):
result = []
temporary = dictionary
for key in dictionary:
if type(dictionary[key]) is not dict:
result.append((key, dictionary[key]))
else:
temporary = dictionary[key]
for item in key_value_generator(temporary):
result.append((key + "." + item[0], item[1]))
return result
def flatten_dict(dictionary):
result = dict()
for pair in key_value_generator(dictionary):
result[pair[0]] = pair[1]
return result
def unflatten_dict(dictionary):
result = dict()
temporary = dictionary
for key in temporary:
if len(key) == 1:
- result[key] = temporary[key]
+ if key in result:
+ internal = result[key]
+ for internal_key in temporary[key]:
+ internal[internal_key] = temporary[key][internal_key]
+ result[key] = internal
+ else:
+ result[key] = temporary[key]
else:
internal = dict()
if key[:-2] in result.keys():
internal = result[key[:-2]]
internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
else:
internal[key[-1]] = temporary[key]
result[key[:-2]] = internal
complex_keys = [key for key in result.keys() if len(key) > 1]
if len(complex_keys) == 0:
return result
else:
return unflatten_dict(result)
def reps(input):
result = []
for item in input:
if input.count(item) > 1:
result.append(item)
- return tuple(result)
+ return tuple(result)