unary star

Alex Martelli aleax at aleax.it
Tue May 6 11:45:56 EDT 2003


VanL wrote:
  ...
> The reason why I like the proposed syntax is because I think that
> while tokens:
>      currtok, *tokens = tokens
>      # Do something with currtok
> 
> is more demonstrative of my intent than my current idiom,
> 
> tokens.reverse()
> while tokens:
>      currtok = tokens.pop()
>      # Do something with currtok

Yes, but,
  for currtok in tokens:
    # do something with currtok

is clearly better yet -- so, this isn't a good use case either way.

There MAY be a decent use case on the left of an unpacking assignment
that is more general -- I do have a few cases of e.g.

    fee, fie, foo = fum[:3]
    fum = fum[3:]

that might read more clearly as

    fee, fie, foo, *fum = fum

Whether this is worth the language complication and risk of confusion,
I don't know.  I'm hovering somewhere between -0 and +0 here.


> Now if you think that my intent is flawed, that is a different argument
> entirely.
> 
> I also think that the **dict outside of function calls is a nice, fairly
> clear shortcut for dict.items()

But that's very far from what ** means in function signatures and
calls.  I can't see any good use case justifying THIS confusion --
most particularly not to encourage the use of .items() when what
one SHOULD be looping on is much more often .iteritems().  -1...


Alex





More information about the Python-list mailing list