Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Open

k #21

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
30 changes: 29 additions & 1 deletion python_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@ def refine_parameters(data: dict):
'''
clean_dict = {}

# Write your code here.
for key, value in data.items():
clean_dict[key] = convert(value)

return clean_dict

def convert(value):
new_value = value
if isinstance(value, list):
new_value = []
for nested_value in value:
new_value.append(convert(nested_value))
elif isinstance(value, dict):
new_value = {}
for nested_key, nested_value in value.items():
new_value[nested_key] = convert(nested_value)
else:
new_value = type_cast(value)
return new_value

def type_cast(value: str):
if value.lower() == 'true':
return True
if value.lower() == 'false':
return False
try:
return int(value)
except ValueError:
try:
return float(value)
except ValueError:
return value