Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions python_solution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,63 @@

def refine_parameters(data: dict):
def is_boolean(string):
''' Return wheter a string is a number
Returns:
Whether a string is a number or not
'''
return string == "true" or string == "false"

def convert_boolean_string(string):
''' Converts a string to its' boolean representation
Returns:
The string as its' boolean representation
'''
if is_boolean:
return string == "true"
else:
raise ValueError

def is_number(string):
''' Return wheter a string is a number
Returns:
Whether a string is a number or not
'''
try:
int(string)
except ValueError:
return False
return True

def convert_string(string):
''' Converts a string to its' datatype representation if applicable
Returns:
A string as it's datatype representation if applicable
'''
if is_boolean(string):
return convert_boolean_string(string)
elif is_number(string):
return int(string)
else:
return string

def refine_parameters(data):
'''Refine the parameters of a dictionary

Returns:
Return a dictionary of cleaned input
'''
clean_dict = {}

# Write your code here.
for key in data:
new_value = data[key]

if type(new_value) == dict:
new_value = refine_parameters(new_value)
elif type(new_value) == list:
for i in range(len(new_value)):
new_value[i] = convert_string(new_value[i])
else:
new_value = convert_string(new_value)

clean_dict[key] = new_value

return clean_dict