Python 从列表列表中选择特定元素
我有一份清单Python 从列表列表中选择特定元素,python,pandas,list,Python,Pandas,List,我有一份清单 grouplst=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]] 我试图做一个类似于每次迭代的操作,这个lstofst被进一步划分为单独的列表。 例如: 我期待的是: In first iteration: lst1=[0,1,2,3,4,5] lst2=[6,7,8,9] #all the elements in lstoflst which are not in lst1 In second iteration: lst1=[3,4,5,6,7
grouplst=[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
我试图做一个类似于每次迭代的操作,这个lstofst被进一步划分为单独的列表。
例如:
我期待的是:
In first iteration:
lst1=[0,1,2,3,4,5]
lst2=[6,7,8,9] #all the elements in lstoflst which are not in lst1
In second iteration:
lst1=[3,4,5,6,7,8]
lst2=[0,1,2,9]
etc.
另外,我通过将numpy数组划分为不同的大小来创建这个grouplst。还有别的办法吗?我试图在没有学习的情况下随机搜索简历 可能类似于itertools导入组合中的
,然后[[list(chain(*x)]用于组合中的x(grouplst,i)]用于范围(1,len(grouplst)]
。?@Chris A我已经尝试过,但这不是正确的输出。
In first iteration:
lst1=[0,1,2,3,4,5]
lst2=[6,7,8,9] #all the elements in lstoflst which are not in lst1
In second iteration:
lst1=[3,4,5,6,7,8]
lst2=[0,1,2,9]
etc.