I got the following algorithm with [3, 7, 5 ,2, 1, 4, 8] input. It is said that is part of QuickSort and it constructs a partition position.. The output should be [3, 1, 2, 5, 7, 4, 8]

I used the following python code:
def partition(x, s, d):
v = x[s]
i = s-1
j = d+1
while i < j:
while True:
i = i+1
if x[i] >=v:
break
while True:
j = j-1
if x[j] <=v:
break
if (i<j):
x[i], x[j] = x[j], x[i]
print (x)
return j
x = [3, 7, 5, 2, 1, 4, 8]
partition(x, 1, 6)
I can't get [3, 1, 2, 5, 7, 4, 8] which is allegedly the right result here. Please help, I tried with different values for s and d which most probably stands for left and right.
UNTIL x[i] >= vhas an index out of range error. @Surt