0

Say I have some code like this:

d = {'range': range}
args = [10]
d['range'](args)

args will be of variable content and length. I can handle any exceptions this would throw... I can't change the function I'm calling (range is builtin), and it would be preferable to not wrap it. How can I make this code function properly?

0

1 Answer 1

6

The functionality that you are looking for is called argument unpacking:

>>> d = {'range': range}
>>> args = [10]
>>> d['range'](*args)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
Sign up to request clarification or add additional context in comments.

1 Comment

see here for more info

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.