反转列表的方式123456a = [1,2,3,4,5,6]a = a[::-1]print(a)[6, 5, 4, 3, 2, 1] 12345a = [1,2,3,4,5,6]a.reverse()print(a)[6, 5, 4, 3, 2, 1] 12345a = [1,2,3,4,5,6]b = sorted(a,reverse=True)print(b)[6, 5, 4, 3, 2, 1] 12345a = [1,2,3,4,5,6]a.sort(reverse=True)print(a)[6, 5, 4, 3, 2, 1] 列表取同1234567891011121314a = [11,22,33]b = [22,33,44]c = []for i in a: # 遍历a if i in b: # 判断交集 c.append(i)print(c)print(list(set(a) & set(b)))print(list(set(a).intersection(set(b))))[22, 33][33, 22][33, 22] 文章作者: 三三不得酒吖文章链接: https://yinshaoxuan.github.io/2020/08/18/work4/版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 斯人若彩虹,遇上方知有!Python练习list上一篇元祖和字典下一篇猜数字 相关推荐 2020-11-0812306模拟买票 2020-11-02豆瓣登陆 2021-01-25pandaswork1 2021-01-27pandaswork2 2020-10-30爬取天气练习 2020-08-18水仙花数 评论