First a simple list approach:
In [41]: alist = [11,12,13,14,15]
In [42]: for i in range(len(alist)):
...: a = alist[:] # copy
...: a[i:i+1]=[] # remove
...: print(a)
...:
[12, 13, 14, 15]
[11, 13, 14, 15]
[11, 12, 14, 15]
[11, 12, 13, 15]
[11, 12, 13, 14]
By working a copy each loop I don't have to put the element back on the original list. If the assignment really required reinsertion I could do (this took a bit more trial-and-error):
In [46]: alist = [11,12,13,14,15]
In [47]: for i in range(len(alist)):
...: a = alist[i]
...: alist[i:i+1]=[] # remove
...: print(alist)
...: alist[i:i]=[a]
...:
[12, 13, 14, 15]
[11, 13, 14, 15]
[11, 12, 14, 15]
[11, 12, 13, 15]
[11, 12, 13, 14]
An array version of this looks simpler:
In [48]: arr = np.array( [11,12,13,14,15])
In [49]: for i in range(len(alist)):
...: a = np.delete(arr, i) # makes a copy
...: print(a)
...:
...:
[12 13 14 15]
[11 13 14 15]
[11 12 14 15]
[11 12 13 15]
[11 12 13 14]
delete
makes a new array, so we don't have to make an explicit copy, nor do we have to reinsert the values. Under the covers delete
is doing something like:
In [50]: for i in range(len(alist)):
...: a = np.concatenate((arr[:i],arr[i+1:]))
...: print(a)
Actually we could do the same thing with the list
In [54]: [alist[:i]+alist[i+1:] for i in range(len(alist))]
Out[54]:
[[12, 13, 14, 15],
[11, 13, 14, 15],
[11, 12, 14, 15],
[11, 12, 13, 15],
[11, 12, 13, 14]]