0

I need to take arguments from a function (f1) and supply mapped arguments to those arguments to another function (f2).

For this I created the argument dictionary against f1 and f2 arguments as under:

def f1(variable,*args):
    arg_dict = {
                'a' : [args1,args2,args3,args4]
                'b' : [args5,args6]
                'c' : [args7,'{:.2f}'.format]
               }
    f2(*args)
    #---do this---
    #---print this---
    return #---this---

But I am unable to think of an efficient and simple way to supply those arguments to f2 inside the f1 function.

Say I do this:

f1(var1,'a','c')

Then the f2 should be run as:

f2(args1,args2,args3,args4,args7,'{:.2f}'.format)

I also thought of asking the f1 arguments as a single value or list under a variable:

def f1(var, param):
    #
    #

So something like this:

f1(var1, ['a','c'])

It should assign ['a','c'] to param under f1. How to proceed next?

1 Answer 1

1

If I'm understanding your problem correctly, then all you need is a way to filter arg_dict by the sets of arguments you actually want to pass, and flatten that set. You can do that by creating a new list and .extend()ing it in a for loop:

def f1(variable,*args):
    arg_dict = {
                'a' : [args1,args2,args3,args4]
                'b' : [args5,args6]
                'c' : [args7,'{:.2f}'.format]
               }
    pass_args = []
    for arg in args:
        if arg in arg_dict:
            pass_args.extend(arg_dict[arg])
    f2(*pass_args)
    #---do this---
    #---print this---
    return #---this---
Sign up to request clarification or add additional context in comments.

1 Comment

Yes. Thank you. I didn't know adding that * in f2 will do the trick. Thanks again.

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.