import copy #导入深拷贝模块
import random # 导入随机数模块
def insert(list1):
list2 = copy.deepcopy(list1) #将排序列表拷贝,list1为排序列表,list2为参考列表
for i in range(1,len(list1)): #循环遍历大于0索引,即从1开始
min = list2[i]
max = list1[i-1]
while min < max: #比较参考列表i索引的元素 与 排序列表 i-1 索引的元素
list1[i] = list1[i-1]
i -= 1
if i >= 0 and list1[i]>min: # 判断是否越界
max = list1[i]
else: #执行插入
i += 1
list1[i] = min
break
return list1
list1 = [ ]
for i in range(10): #循环生成一个长度为10,元素在[0,20)之间的范围内
list1.append(random.randrange(20))
print(insert(list1))