[SOLVED] Call a function from dictionary by outputting numbers as strings in quotes

Issue

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?

Solution

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.

Answered By – Orius

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *