在 Python 中,如何将元组列表加入一个列表? [英] in Python, How to join a list of tuples into one list?
本文介绍了在 Python 中,如何将元组列表加入一个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
继我之前的问题如何将列表项分组为元组?一个>
如果我有一个元组列表,例如
If I have a list of tuples, for example
a = [(1,3),(5,4)]
如何解包元组并将其重新格式化为一个列表
How can I unpack the tuples and reformat it into one single list
b = [1,3,5,4]
我认为这也与 iter
功能有关,但我真的不知道如何做到这一点.请赐教.
I think this also has to do with the iter
function, but I really don't know how to do this. Please enlighten me.
推荐答案
b = [i for sub in a for i in sub]
这样就行了.
这篇关于在 Python 中,如何将元组列表加入一个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文