1

I would like to run the following in iPython:

mylist = ['a','b']
def f(a,b):
    do_something

sliderinterval=(0,10,1)
w = interactive(f, a = sliderinterval, b = sliderinterval)

but instead of writing a and b, I would like to take them from mylist. Is that possible?

1 Answer 1

1

Make a dict comprehension, and then pass the dictionary to the function by unpacking (**) in as keywords arguments.

mylist = ['a','b']
def f(a,b):
    print(a,b)

sliderinterval=(0,10,1)
d = {k:sliderinterval for k in mylist}
w = interactive(f, **d)

**d is equivalent to writing manually key1=value1, key2=value2... you will often see it in function signature as **kwargs or **kw, for unpacking list you will need only one star and see to as *args.

Sign up to request clarification or add additional context in comments.

Comments

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.