I need to make a permutation that looks like a sequence of 1-N with a 0 stuffed in place #k.
This method works, but is there anything simpler using builtin functions?
def permshift(n,k):
return [0 if x == k else x+(x<k) for x in range(n)]
>>> permshift(7,0)
[0, 1, 2, 3, 4, 5, 6]
>>> permshift(7,1)
[1, 0, 2, 3, 4, 5, 6]
>>> permshift(7,2)
[1, 2, 0, 3, 4, 5, 6]
>>> permshift(7,3)
[1, 2, 3, 0, 4, 5, 6]
>>> permshift(7,4)
[1, 2, 3, 4, 0, 5, 6]
>>> permshift(7,5)
[1, 2, 3, 4, 5, 0, 6]
>>> permshift(7,6)
[1, 2, 3, 4, 5, 6, 0]
Just create a new list, and insert the
0wherever you need to.