给定(a, b, (c, d, e, f), g)
如何自动提取(c, d, e, f)
? (不是通过显式地一一提取变量并将它们添加到列表或其他内容中)
最佳答案
如果您想从列表中提取第一个元组,只需执行以下操作:
tup = ('a', 'b', ('c', 'd', 'e', 'f'), 'g')
# Get first tuple
print (_ for _ in tup if type(_) is tuple).next()
# ('c', 'd', 'e', 'f')
关于python - 在Python中从元组中提取元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28909447/