Ignore part of a python tuple Ignore part of a python tuple python python

Ignore part of a python tuple


I personally would write:

a, _, b = myTuple

This is a pretty common idiom, so it's widely understood. I find the syntax crystal clear.


Your solution is fine in my opinion. If you really have a problem with assigning _ then you could define a list of indexes and do:

a = (1, 2, 3, 4, 5)idxs = [0, 3, 4]a1, b1, c1 = (a[i] for i in idxs)


Note that you can slice the source tuple, like this instead:

a,b = some_tuple[0:2]