相关疑难解决方法(0)

Python:将列表列表转换为元组元组

一个Python新手!我需要帮助转换列表元组列表的列表.

我想调用append_as_tuples函数,但每次返回它时,它都说
它只能将列表(不是元组)连接到列表

这是我到目前为止:

def append_as_tuple(t, l):
    ''' Convert list l to a tuple and append it to tuple t as a single value '''
    return t[:] + (tuple(l),)  

def convert_lists(lol):
    t = []
    if type(lol) == a or type(lol) == tuple:
        return [convert_lists(lol) for i in t]
    return append_as_tuples(lol,a)

#- test harness#

a=[range(5), range(10,20), ['hello', 'goodbye']]  
print a  
print convert_lists(a)  
print convert_lists([])  
Run Code Online (Sandbox Code Playgroud)

python tuples function list

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

function ×1

list ×1

python ×1

tuples ×1