I have a dictionary that I want to use to call a function. My problem is, that the input needed for the function must be in quotes. My dict is like this:
dict = {
'test': [10, 14, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48]
}
and my function has to get these numbers like this:
testfunction(["10", "14", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"])
Is there a good - maybe Pythonic - way to solve this?
CodePudding user response:
If you can, you probably should just change testfunction
.
If that's impossible, you can use list(str(n) for n in dict["test"])
, which transforms the given dictionary into a list of strings, and pass it as the argument to testfunction
.
CodePudding user response:
You could map
d['test']
to strings and unpack it in a list:
>>> print([*map(str, d['test'])])
['10', '14', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48']