2017-02-28 46 views
0

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

代码so远:

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]

回答

0
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()