如何根据索引子列表对group
或batch
元素进行列表?
下面是应该考虑的可能情况.希望这会有更好的帮助.
长度为elements
的1st Instance :==所有indices
个元素的总和
indices = [1, 3, 5]
elements = ['A','B','C','D','E','F','G','H','I']
Output:
[['A'], ['B','C','D'],['E','F','G','H','I']]
2nd Instance :个elements
的长度;全部indices
个元素的总和
应考虑最大元素为indices
,然后相应地分组elements
列表
indices = [1, 3, 5]
elements = ['A','B','C','D','E','F','G','H','I', 'J','K','L','M','N']
Output:
[['A'], ['B','C','D'],['E','F','G','H','I'],['J','K','L','M','N']]
3rd Instance :个elements
的长度;全部indices
个元素的总和
应考虑最大元素为indices
,然后相应地分组elements
列表
indices = [1, 3, 5]
elements = ['A','B','C','D','E','F','G','H','I', 'J','K','L']
Output:
[['A'], ['B','C','D'],['E','F','G','H','I'],['J','K','L']]
4th Instance :个elements
的长度;全部indices
个元素的总和
应考虑最大元素为indices
,然后相应地分组elements
列表
indices = [1, 3, 5]
elements = ['A','B','C','D','E','F','G','H','I', 'J','K','L','M','N','O','P','Q','R','S']
Output:
[['A'], ['B','C','D'],['E','F','G','H','I'],['J','K','L','M','N'], ['O','P','Q','R','S']]
5th Instance :长度为elements
;全部indices
个元素之和
indices = [1, 3, 5]
elements = ['A','B','C']
Output:
[['A'], ['B','C']]
6th Instance :长度为elements
;全部indices
个元素之和
indices = [1, 3, 5]
elements = ['A','B','C','D','E','F']
Output:
[['A'], ['B','C','D'],['E','F']]
How can I achieve this in Python ?个