grouping a flat list of number by range
Steven Bethard
steven.bethard at gmail.com
Sun Jun 4 14:11:21 EDT 2006
joh12005 at yahoo.fr wrote:
>> ... _, first_n = group[0]
>
> what is the meaning of the underscore "_" ? is it a special var ? or
> should it be readed as a way of unpacking a tuple in a non useful var ?
> like
>
> lost, first_n = group[0]
Yep, it's just another name. "lost" would have worked just as well.
It's pretty typical around here to see "_" used when a tuple is unpacked
but some of the values aren't used. So if you see something like::
for _, dirs, _ in os.walk(top):
...
it just means that the "..." code is only going to use "dirs" (not the
root path or files that are also available from the os.walk() iterator).
STeVe
More information about the Python-list
mailing list