【发布时间】:2021-05-24 13:43:44
【问题描述】:
我想为一个数组创建所有可能的排列,其中每个元素只能出现一次,并限制元素数组索引位置。
ID = ["A","B","C","D","E","F","G","H","I","J"]
我想创建 original_array 的所有可能排列,但是每个元素的位置都限制在以下给出的索引位置:
ID = ["A","B","C","D","E","F","G","H","I","J"]
Index_Options=[]
for i in range(len(ID)):
List1=[]
distance=3
value = i - distance
for j in range((int(distance)*2)):
if value < 0 or value > len(ID):
print("Disregard") #Outside acceptable distance range
else:
List1.append(value)
value=value+1
Index_Options.append(List1)
print(Index_Options)
#Index_Options gives the possible index positions for each element. ie "A" can occur in only index positions 0,1,2, "B" can occur in only index positions 0,1,2,3 ect.
我只是在努力研究如何使用这些信息来创建所有输出排列。
任何帮助将不胜感激
【问题讨论】:
标签: python iteration permutation itertools