unary star

VanL vlindberg at verio.net
Tue May 6 11:19:44 EDT 2003


> 
> and you don't need to reverse(), pop(), reverse().
> You do know that you can use pop(x), with x=0, to
> effectively pop the first item on a list?
> 
> -gustavo
> 

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

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()


VanL





More information about the Python-list mailing list