在长度为1的列表中解压1元组 [英] Unpacking a 1-tuple in a list of length 1
本文介绍了在长度为1的列表中解压1元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在这样的列表中有一个元组:
Suppose I have a tuple in a list like this:
>>> t = [("asdf", )]
我知道列表始终包含一个1元组.目前,我正在这样做:
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?
推荐答案
>>> t = [("asdf", )]
>>> t[0][0]
'asdf'
这篇关于在长度为1的列表中解压1元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文