我有以下代码:

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))时,它给了我这个结果:

('43009',)
('43189', '43619')
('42319', '28109')
('42319', '28109', '28189')
('03239', '03211')
('E0599', '03531')


我如何使其成为一个元组?即
('43009','43189', '43619', '42319', '28109', '42319', '28109', '28189', '03239', '03211', 'E0599', '03531')

最佳答案

tuples = (('hello',), ('these', 'are'), ('my', 'tuples!'))
sum(tuples, ())


在我的Python版本(2.7.12)中给出('hello', 'these', 'are', 'my', 'tuples!')。事实是,我在尝试找到它的工作原理时发现了您的问题,但希望对您有用!

关于python - 如何连接元组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35534184/

10-12 19:26