def sort_the_odd(nums:list=None):
""""""
# print(nums)
odd_number= sorted([n for n in nums if n%2!=0]) #过滤出奇数并排序
for index in range(len(nums)):
if nums[index]%2 != 0:#奇数
nums[index] = odd_number[0] #将源列表中的奇数依次替换掉排好序的奇数
odd_number.pop(0)
return nums
def sort_the_odd2(nums:list=None):
even_num = [(nums.index(num),num) for num in nums if num%2 == 0] #拿源列表偶数的位置和值
odd_number= sorted([n for n in nums if n%2!=0]) #过滤出奇数并排序
for index,num in even_num:
odd_number.insert(index,num) #在奇数队列中插入偶数
return odd_number
def sort_the_odd(li):
li_length=len(li)
li1=[]
li2=[]
for i in range(li_length):
if li[i]%2==1:
li1.append(i)
li2.append(li[i])
for i in range(len(li2)-1):
for j in range(len(li2)-1-i):
if li2[j]>li2[j+1]:
li2[j],li2[j+1]=li2[j+1],li2[j]
for i in range(len(li2)):
li[li1[i]]=li2[i]
return li