当前位置:网站首页>问题1:给你1-10的列表,实现列表输出,单数在左边,双数在右边。
问题1:给你1-10的列表,实现列表输出,单数在左边,双数在右边。
2022-07-31 03:42:00 【理不尽的神之手】
# 给你1-10的列表,实现列表输出,单数在左边,双数在右边。
numbers = [] # 创建一个空列表,存储奇数列表,偶数列表
# 列表解析方式,获取1-10中的偶数
even_numbers = [number for number in range(1, 11) if not number % 2]
# 获取1-10中的奇数
odd_numbers = [number for number in range(1, 11) if number % 2]
# list_name.extend(list_name2):将list_name2 追加到list_name中
numbers.extend(even_numbers)
numbers.extend(odd_numbers)
print(numbers)
# [2, 4, 6, 8, 10, 1, 3, 5, 7, 9]
边栏推荐
- Distributed locks and three implementation methods
- Pytest e-commerce project combat (on)
- Use of QML
- 数据库文件中的未分配的块和未使用的块的区别
- (5) final, abstract class, interface, inner class
- Observer pattern
- Ambiguous method call.both
- [Compilation principle] Lexical analysis program design principle and implementation
- 数据库实现分布式锁
- [AUTOSAR-RTE]-5-Explicit (explicit) and Implicit (implicit) Sender-Receiver communication
猜你喜欢
LeetCode每日一练 —— 138. 复制带随机指针的链表
Port inspection steps - 7680 port analysis - Dosvc service
Understanding and Using Unity2D Custom Scriptable Tiles (4) - Start to build a custom tile based on the Tile class (below)
Learning DAVID Database (1)
No qualifying bean of type 问题
Know the showTimePicker method of the basic components of Flutter
IDEA comment report red solution
type_traits元编程库学习
The BP neural network
Detailed explanation of TCP (1)
随机推荐
Daily practice of LeetCode - 138. Copy a linked list with random pointers
Observer pattern
"DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction" paper notes
Day32 LeetCode
Detailed explanation of TCP and UDP
Pytest e-commerce project combat (on)
Redis 使用LIST做最新评论缓存
数据库文件中的未分配的块和未使用的块的区别
从滴滴罚款后数据治理思考
LeetCode每日一练 —— 138. 复制带随机指针的链表
Mysql 45 study notes (twenty-five) MYSQL guarantees high availability
Safety 20220709
Problems that need to be solved in distributed system architecture
A brief introduction to the CheckboxListTile component of the basic components of Flutter
Bubble sort, selection sort, insertion sort, binary search directly
Learning DAVID Database (1)
(四)递归、可变参数、访问修饰符、理解 main 方法、代码块
Redis uses sorted set to cache latest comments
STM32 problem collection
IDEA common shortcut keys and plug-ins