unary star

sismex01 at hebmex.com sismex01 at hebmex.com
Tue May 6 11:37:16 EDT 2003


> 
> FWIW, I usually only reverse once, then pop repeatedly.  I 
> have found it a useful idiom for parsing mini-languages that
> don't require a more comprehensive solution -- just get the
> list of tokens, reverse, and pop them off.
> 
> 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
>

When you use:

    L.reverse()
    while L:
        item = L.pop()
        ...

At least in Python, it's perfectly understandable.
Or, to put it in another way, it's "Pythonic".
 
> Now if you think that my intent is flawed, that is a 
> different argument entirely.

Of course not, that would be pretty dumb of my part,
you know what you are doing, and by the example you
show, you also know *how* to do it.

> 
> I also think that the **dict outside of function calls is a 
> nice, fairly clear shortcut for dict.items()
> 

But...

Back when I perled more often, I found the language (Perl)
to be full of shortcuts.  I'm sure that most of them found
their way into the language by means of "It'd be nice to
have ...", which in it's moment would have been nice.

But, the final result is that, as a language, Perl leaves
a lot to be desired because it's a mishmash of everybody
and his dog's favorite shortcuts.  And that's not really
a good thing.

Python's nice to make small hacks in because it's lack of
"magical chars" and things like that.  Using "*" to slice
the first item off a list, and return a tuple with that
item and the remaining list, sounds "Perly" to me, ugly,
it's suddenly not as readable, not "wordy" like Python
normally is.

So... That's my intent.

-gus





More information about the Python-list mailing list