On Wed, Feb 11, 2015 at 8:44 AM, eryksun <[email protected]> wrote: > On Wed, Feb 11, 2015 at 7:27 AM, boB Stepp <[email protected]> wrote: >> >> pass_args = {'a': (x1, x2, x3), 'b': (y1, y2), 'c': (z)} >> call_fcn[key_letter](key_letter) >> >> But ran into the syntax error that I was giving one argument when >> (possibly) multiple arguments are expected. > > Do it like this: > > pass_args = { > 'a': (x1, x2, x3), > 'b': (y1, y2), > 'c': (z,), > } > > call_fcn[key_letter](*pass_args[key_letter]) > > Note the 'c' tuple is written as (z,). A comma is required to create a > tuple. Also note the call uses the "* expression" syntax to merge an > iterable with the call's positional arguments. For example, f(x0, > *(x1,x2,x3)) is equivalent to f(x0, x1, x2, x3). Refer to the glossary > definition of "argument", and for a more detailed discussion, see the > section on calls in the language reference.
I was trying to puzzle out this "* expression" syntax from "Learning Python, 4th Ed." from a more general table of function argument-matching forms (author's table 18-1) when your post arrived. Your explanation cleared things up immediately. Thanks! -- boB _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
