unary star

holger krekel pyth at devel.trillke.net
Sun May 4 11:04:28 EDT 2003


"Martin v. L?wis" wrote:
> David Eppstein wrote:
> 
> > That is, since (non-keyworded) function arguments are a lot like tuples, 
> > why isn't there a unary star pseudo-operator to expand a sequence into 
> > the end of a tuple or list expression?
> 
> Because the similarity is shallow: Just look at keyword and optional 
> arguments, and you notice quickly that function parameters and tuples 
> are entirely different concepts.
> 
> That is, in a limited number of cases, you can use tuples to represent 
> actual parameters, but that's about it. The *args and **args notations 
> are a convience; a shortcut for invoking apply(). A similar shortcut is 
> not needed for tuples, and hence it is not (and should not be) supported.

I can see good uses for getting the unary-star syntax "*args" 
in other than function call contexts. E.g.

    head, *rest = l

could be made to mean

    head = l[0]
    rest = l[1:]

of which the former looks more readable to me.  And David's basic idea of 

    t = [front, *l, back]

looks more readable to me than

    t = [front] + l + [back]

Anyway, trying to leverage the unary-star syntax for other than 
"function call parameter" contexts seems worthwhile to me.  

    holger





More information about the Python-list mailing list