Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
38 changes: 31 additions & 7 deletions python_solution.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@

def convert(string: str):
# check for bools
if string == 'true':
return True
if string == 'false':
return False

# check for ints and strings
try:
number = int(string)
if str(number) == string:
return number
else:
return string
except (TypeError, ValueError) as e:
return string

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

Returns:
Return a dictionary of cleaned input
'''

clean_dict = {}

# Write your code here.
for key, val in data.items():
# if we encounter a dictionary - refine that
if type(val) == dict:
clean_dict[key] = refine_parameters(val)
continue

# if we encounter a list - convert each element
if type(val) == list:
clean_dict[key] = list(map(convert, val))
continue

# if we encounter anything else - convert that
clean_dict[key] = convert(val)

return clean_dict
2 changes: 1 addition & 1 deletion tests/test_python_solution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from python_solution import refine_parameters
from ..python_solution import refine_parameters


def test_refine_parameters():
Expand Down