Pythonic方法生成可能的数组列表

Dan*_*ang 2 python

给定一个数组(例如[3,5,2]),我试图生成一个可能的数组列表,这些数组是在数组中添加1到1个条目得到的:[[4,5,2],[3 ,6,2],[3,5,3]].

我可以通过以下方式完成它,但想知道是否有更多的pythonic方式来获得结果?

test = [3, 5, 2]
result = [t.copy() for _ in range(len(test))]
for index, _ in enumerate(result):
    result[index][index] += 1
Run Code Online (Sandbox Code Playgroud)

PM *_*ing 6

以下是如何使用列表理解来完成它:

test = [3, 5, 2]   
print [test[:i] + [v + 1] + test[i+1:] for i,v in enumerate(test)]
Run Code Online (Sandbox Code Playgroud)

产量

[[4, 5, 2], [3, 6, 2], [3, 5, 3]]
Run Code Online (Sandbox Code Playgroud)