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?

Thaddeus Hughes
  • 307
  • 4
  • 11

1 Answers1

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]
>>>
  • [see here](http://stackoverflow.com/questions/36901/what-does-double-star-and-star-do-for-python-parameters) for more info – Adam Smith Aug 05 '14 at 20:30