I have a working simple insertion sort algorithm written in Python. What I'm trying to do is take the output and put it in a new list without altering the original input list. I've been stuck on trying to figure out how to do this and maybe I'm just overthinking it, but I thought I would see if anyone could help. Thanks!
#!/usr/local/bin/python
import sys
import random
def RandomArray(n, max):
A = []
i = 1
while i <= n:
v = random.randint(1, max+1)
if v not in A:
A.append(v)
i = i + 1
return A
A = RandomArray(10,100)
print(A)
def InsertionSort(A):
element = 1
for element in range(0, (len(A))):
w = A[element]
j = element - 1
while (j >= 0) & (A[j] > w):
A[j+1] = A[j]
j = j - 1
A[j+1] = w
return A
print(InsertionSort(A))
InsertionSort(A[:])) or refactor the function accordingly. Note that functions that mutate their inputs should returnNoneby convention.