写个python程序:D盘根目录下有一组数据 :12,34,13,9,8,56,13,45,11 ,12 ,14,45,582,15,67,8,要求把上述一组数据进行排序如果是相同的数据,仅保留其中一个,代码实现用python编写(不用sorted函数实现 )
时间: 2024-05-24 08:12:01 浏览: 24
nums = [12, 34, 13, 9, 8, 56, 13, 45, 11, 12, 14, 45, 582, 15, 67, 8]
# 冒泡排序
for i in range(len(nums)):
for j in range(len(nums)-1-i):
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
# 去重
result = []
for num in nums:
if num not in result:
result.append(num)
print(result)
阅读全文