I have a tuple foo which contains something I don’t care about and something I do.
foo = (something_i_dont_need, something_i_need)
Is it more correct to use
_, x = foo
or
x = foo[1]
The only things I can think of are different behaviour if foo isn’t of length two.
I suppose this is fairly case-specific, but is one of these the de-facto pythonic way of doing things?
I think the usual way of doing it
Using
_is less common, and I think also discouraged. Using_is also unwieldy when you need only a few elements out of a longtuple/list. Slicing also comes handy when you are only choosing a contiguous subsequence.But at the end of the day I think it is just a matter of subjective preference. Use whatever that looks more readable to you and your team.