如何加入众多“上市"在 Python 中元组变成一个元组? [英] How to join many "listed" tuples into one tuple in Python?

查看:34
本文介绍了如何加入众多“上市"在 Python 中元组变成一个元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 中,如何将元组列表加入一个列表?如何在 Python 中合并两个元组?如何在 Python 中合并任意数量的元组?.所有答案都参考元组列表,所以那里提供的解决方案对我来说似乎没用.

There are few answers for the problem on in Python, How to join a list of tuples into one list?, How to merge two tuples in Python?, How To Merge an Arbitrary Number of Tuples in Python?. All the answers refer to list of tuples, so the solutions provided there seem to be useless for me.

这是我的问题,我有一个包含如下元组的文件:

Here is my problem, I have a file with tuples listed like this:

(1, 5)

(5, 3)

(10, 3)

(5, 4)

(1, 3)

(2, 5)

(1, 5)

我想像这样将它们加入一个元组:

I would like to join them in ONE tuple like this:

((1, 5), (5, 3), (10, 3), (5, 4), (1, 3), (2, 5), (1, 5))

((1, 5), (5, 3), (10, 3), (5, 4), (1, 3), (2, 5), (1, 5))

谁能帮我解决这个问题?

Can anyone help me to solve this problem?

谢谢

推荐答案

a = (1, 5)

b = (5, 3)

c = (10, 3)

d = (5, 4)

e = (1, 3)

f = (2, 5)

g = (1, 5)

tul = (a, b, c, d, e, f, g)

print(tul)

这篇关于如何加入众多“上市"在 Python 中元组变成一个元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆