【发布时间】:2019-08-10 10:25:53
【问题描述】:
我有一个数组,每个索引将跟随另一个索引,并且索引不会跟随相同的索引。在该索引为当前索引之后,索引将跟随索引为目标
这是python的代码
list_value = [1,2,3]
for current in range(len(list_value)):
for target in range(len(list_value)):
if current == target: continue
list_target.append(target)
预期输出为{current:0, target:[1,2,0,2,0,1]}
但我需要的结果是
{current:0, target:[1,2]}
{current:1, target:[0,2]}
{current:2, target:[0,1]}
我只添加新目标并重复直到 list_value 的长度完成,我需要帮助,请
非常感谢
【问题讨论】:
标签: arrays python-3.x sorting dictionary indexing