时间:2021-07-01 10:21:17 帮助过:6人阅读
nums = [6, 11, 7 ,9, 4, 2,1] i = len(nums) - 1 j = 1 while j < i: if nums[j] > nums[j+1]: nums[j], nums[j+1] = nums[j+1], nums[j] j += 1 print(nums) lst = sorted(nums) print(lst) lst = sorted(nums, reverse=True) print(lst)
结果:
[6, 7, 9, 4, 2, 1, 11]
[1, 2, 4, 6, 7, 9, 11]
[11, 9, 7, 6, 4, 2, 1]
以上就是关于python排序求最大值第二最大的方法的详细内容,更多请关注Gxl网其它相关文章!