当前位置:网站首页>Example 040: Reverse List
Example 040: Reverse List
2022-08-04 01:39:00 【Lazy laughing】
Title: Output an array in reverse order.
Program Analysis: Swap positions in sequence, or call the reverse method directly.
Code:
Method one:
lis = [1, 10, 100, 1000, 10000, 100000]for i in range(int(len(lis) / 2)):lis[i], lis[len(lis) - 1 - i] = lis[len(lis) - 1 - i], lis[i]print(lis)
Method Two:
lis = [1, 10, 100, 1000, 10000, 100000]print(lis[::-1])
Method three:
lis.reverse()print(lis)
Results:
"""Problems encountered during study and no one answered?The editor has created a QQ group for Python learning and communication, and you can enter the officially recommended group by scanning the code below.Looking for like-minded friends to help each other, there are also good video learning tutorials and PDF e-books in the group!↓↓↓↓↓↓"""
边栏推荐
- typescript57 - Array generic interface
- appium软件自动化测试框架
- 螺旋矩阵_数组 | leecode刷题笔记
- 一篇文章看懂JS闭包,从执行上下文角度解析有趣的闭包
- boot issue
- 实例035:设置输出颜色
- Slipper —— 虚点,最短路
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- flask框架初学-06-对数据库的增删改查
- [store mall project 01] environment preparation and testing
猜你喜欢
JS 从零教你手写节流throttle
flask框架初学-06-对数据库的增删改查
Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system
lombok注解@RequiredArgsConstructor的使用
esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)
initramfs详解----添加硬盘驱动并访问磁盘
Flask框架初学-05-命令管理Manager及数据库的使用
redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
MySQL回表指的是什么
持续投入商品研发,叮咚买菜赢在了供应链投入上
随机推荐
Promise 解决阻塞式同步,将异步变为同步
工程制图平面投影练习
MongoDB数据接入实践
nodejs+npm的安装与配置
Quickly build a website with static files
How to find the cause of Fiori Launchpad routing errors by single-step debugging
持续投入商品研发,叮咚买菜赢在了供应链投入上
OpenCV如何实现Sobel边缘检测
splice随机添加和删除的写法
工程制图复习题
Intranet penetration - application
Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system
浏览器存储
2022年上半年各大厂Android面试题整理及答案解析(持续更新中......)
一个注解替换synchronized关键字:分布式场景下实现方法加锁
typescript51 - basic use of generics
静态/动态代理模式
谁说程序员不懂浪漫,表白代码来啦~
简单的线性表的顺序表示实现,以及线性表的链式表示和实现、带头节点的单向链表,C语言简单实现一些基本功能
jmeter distributed stress test