当前位置:网站首页>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!↓↓↓↓↓↓"""边栏推荐
- 有没有jdbc 链接优炫数据库文档及示例?
- MySQL回表指的是什么
- Demand analysis of MES management system in electronic assembly industry
- 静态/动态代理模式
- 工程制图名词解释-重点知识
- Hey, I had another fight with HR in the small group!
- idea中diagram使用
- Promise solves blocking synchronization and turns asynchronous into synchronous
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- typescript52 - simplify generic function calls
猜你喜欢

Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中

Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system

typescript57 - Array generic interface

企业虚拟偶像产生了实质性的价值效益

splice随机添加和删除的写法

GraphQL背后处理及执行过程是什么

nodejs+express realizes the access to the database mysql and displays the data on the page

HBuilderX的下载安装和创建/运行项目

5. Scrapy middleware & distributed crawler

字符串的排列
随机推荐
OpenCV如何实现Sobel边缘检测
ThreadLocal
GraphQL背后处理及执行过程是什么
.NET Static Code Weaving - Rougamo Release 1.1.0
LDO investigation
字符串变形
GNSS【0】- 专题
【OpenCV】-重映射
Use nodejs switch version (no need to uninstall and reinstall)
多渠道打包
持续投入商品研发,叮咚买菜赢在了供应链投入上
一个注解替换synchronized关键字:分布式场景下实现方法加锁
多线程 之 JUC 学习篇章一 创建多线程的步骤
DDTL:远距离的域迁移学习
持续投入商品研发,叮咚买菜赢在了供应链投入上
数组_滑动窗口 | leecode刷题笔记
Sticker Spelling - Memory Search / Shape Pressure DP
实例037:排序
Installation and configuration of nodejs+npm
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"