Search code examples
pythonlisttuplesiterable-unpacking

Unpacking a 1-tuple in a list of length 1


Suppose I have a tuple in a list like this:

>>> t = [("asdf", )]

I know that the list always contains one 1-tuple. Currently I do this:

>>> dummy, = t
>>> value, = dummy
>>> value
'asdf'

Is there a shorter and more elegant way to do this?


Solution

  • >>> t = [("asdf", )]
    >>> t[0][0]
    'asdf'