python - 如何在不改变python中元素位置的情况下对列表列表中的元素进行排序?

标签 python

我有 list :

a = [[7, 3, 5], [9, 0, 3], [1, 2, 3]]

预期输出:

b = [[7, 5, 3], [9, 3, 0], [3, 2, 1]]

提前致谢!

最佳答案

您可以使用列表理解并使用sorted(l,verse=True)按降序对每个子列表进行排序

a = [[7, 3, 5], [9, 0, 3], [1, 2, 3]]
b = [sorted(l, reverse=True) for l in a]

关于python - 如何在不改变python中元素位置的情况下对列表列表中的元素进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68584022/

相关文章:

Python 数据抓取

Python 3.3 无法导入地穴

python re.sub 非贪婪替代失败,字符串中有换行符

Python 从列表中删除每个字符串中的单词

python - 将 py 文件转换为 exe,找不到现有的 PyQt5 插件目录

python - python 的 ctypes c_char 是否适用于 Windows 64?

python - Selenium Python 在 VPS 中设置 Chrome 默认下载目录

python - Scikit 学习 API xgboost 允许在线培训吗?

Python url标题问题

python - 将列表列表转换为字典