List 使用索引和切片从嵌套列表中提取

List 使用索引和切片从嵌套列表中提取,list,indexing,slice,List,Indexing,Slice,这是我当前的列表:[0,[],[1,2,3,4],[5],[6,7],[8,9,10]] 要使用索引和切片从列表和嵌套项中提取,这就是我要提取的内容:[0,2,3,5,6,8,10] L = [0, [], [1,2,3,4], [[5],[6,7]], [8,9,10]] new_list = [L[0], L[2][1], L[2][2], [L[3][0][0], L[3][1][0]], L[-1][-3], L[-1][-1]] print("new list is", new_lis

这是我当前的列表:[0,[],[1,2,3,4],[5],[6,7],[8,9,10]] 要使用索引和切片从列表和嵌套项中提取,这就是我要提取的内容:[0,2,3,5,6,8,10]

L = [0, [], [1,2,3,4], [[5],[6,7]], [8,9,10]]
new_list = [L[0], L[2][1], L[2][2], [L[3][0][0], L[3][1][0]], L[-1][-3], L[-1][-1]]
print("new list is", new_list) 
print()
迄今为止的代码:

    list = [0, [], [1,2,3,4], [[5],[6,7]], [8,9,10]]
new_list = list[0], list[2], list[3], list[4]
print("new list is", new_list)
输出:新列表是(0、[1,2,3,4]、[5]、[6,7]、[8,9,10]),需要提取下一个项目并按如下方式格式化列表:[0,2,3、[5,6]、8,10]

L = [0, [], [1,2,3,4], [[5],[6,7]], [8,9,10]]
new_list = [L[0], L[2][1], L[2][2], [L[3][0][0], L[3][1][0]], L[-1][-3], L[-1][-1]]
print("new list is", new_list) 
print()