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)
<
Another possibility is to create a named tuple and use that in your return value. Then you can access the value you want by "name."
MyTuple = collections.namedtuple('MyTuple', 'ignored needed')
Then you can make
foo = (something_i_dont_need, something_i_need)
into
foo = MyTuple(something_i_dont_need, something_i_need)
and then say
x = foo.needed
instead of
x = foo[1]
Performance-wise, this may not be the best. But I think it can sometimes make writing and understanding the code easier. And it is an alternative to some of the other solutions.