grouping a flat list of number by range

J

joh12005

Hello
... _, 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]

best regards.
 
S

Steven Bethard

... _, 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
 
K

K.S.Sreeram

Yup! '_' is just used as a dummy. Its a pretty common idiom. There's
nothing special about that variable.

Hello
... _, 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]

best regards.



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEgyKIrgn0plK5qqURAoloAJ9eU5hXHkBbQjL178EbQcXpShhplwCgqNP2
RWz6aT3MHAT34VO55ndM0KY=
=xuv0
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top