python - 在Python中从元组中提取元组

标签 python tuples

给定(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/

相关文章:

Python,如果包含匹配的元组,则删除整个列表

php - PHP中有元组吗?

Python:GUI - 绘图,从实时 GUI 中的像素读取

python - 从 python 脚本,更改用户,设置环境并运行几个命令

python - 如何让Python显示超过50位小数?

对于公共(public)方法,Python 模拟补丁无法按预期工作

python - 按整数排列元组列表

python - 从 python 中的元组的元组中获取元素

python - Python 中模块级常量的元组与列表?

python - 多个指标的相关性