可以使用extend()方法将两个列表合并,再使用sorted()方法对新列表进行降序排序。

代码如下:

lst_odd = [1, 3, 5, 7, 9] lst_even = [2, 4, 6, 8, 10]

使用extend()方法将两个列表合并

new_lst = lst_odd.copy() new_lst.extend(lst_even)

使用sorted()方法对新列表进行降序排序

new_lst = sorted(new_lst, reverse=True)

print(new_lst) # 输出:[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

用python设有列表lst_odd=13579和列表lst_even=246810。试编写程序将两个列表合并成一个新的列表并将新列表按照元素的大小降序排列。【要求】不改变列表lst_odd 和lst_even的元素。

原文地址: https://www.cveoy.top/t/topic/bZMv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录