一个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)