本文介绍了如何连接元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
def make_service(service_data, service_code):
routes = ()
curr_route = ()
direct = ()
first = service_data[0]
curr_dir = str(first[1])
for entry in service_data:
direction = str(entry[1])
stop = entry[3]
if direction == curr_dir:
curr_route = curr_route + (stop, )
print((curr_route))
当我打印时((curr_route)) ,它给了我这个结果:
When I print((curr_route)), it gives me this result:
('43009',)
('43189', '43619')
('42319', '28109')
('42319', '28109', '28189')
('03239', '03211')
('E0599', '03531')
如何使它成为一个元组?即
('43009','43189','43619','42319','28109','42319','28109','28189','03239','03211 ','E0599','03531')
How do I make it one tuple? i.e.('43009','43189', '43619', '42319', '28109', '42319', '28109', '28189', '03239', '03211', 'E0599', '03531')
推荐答案
tuples = (('hello',), ('these', 'are'), ('my', 'tuples!'))
sum(tuples, ())
给出(你好,这些,是,我,元组! )
在我的Python版本(2.7.12)中。事实是,我试图找到如何时发现了您的问题,但希望对您有用!
gives ('hello', 'these', 'are', 'my', 'tuples!')
in my version of Python (2.7.12). Truth is, I found your question while trying to find how this works, but hopefully it's useful to you!
这篇关于如何连接元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!