当前位置:网站首页>问题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]
边栏推荐
- some of my own thoughts
- Redis implements distributed locks
- [Compilation principle] Design principle and implementation of recursive descent parsing
- els block to the right
- C primer plus study notes - 8, structure
- 组件传值 provide/inject
- (线段树) 基础线段树常见问题总结
- (六)枚举、注解
- 【CocosCreator 3.5】CocosCreator get network status
- Postgresql 15 source code analysis (5) - pg_control
猜你喜欢

Daily practice of LeetCode - 138. Copy a linked list with random pointers

Detailed explanation of TCP and UDP

Why don't you programmers make a living off your own projects?And have to work for someone else?

《DeepJIT: An End-To-End Deep Learning Framework for Just-In-Time Defect Prediction》论文笔记

A brief introduction to the showDatePicker method of the basic components of Flutter

What is a system?

No qualifying bean of type 问题

What skills do I need to learn to move from manual testing to automated testing?

Zotero如何删除自动生成的标签

The BP neural network
随机推荐
【SemiDrive源码分析】【MailBox核间通信】44 - 基于Mailbox IPCC RPC 实现核间通信(RTOS侧 IPCC_RPC Server 消息接收及回复 原理分析篇)
Several common errors when using MP
Pytest电商项目实战(上)
Point Cloud DBSCAN Clustering (MATLAB, not built-in function)
Notes on the establishment of the company's official website (6): The public security record of the domain name is carried out and the record number is displayed at the bottom of the web page
Port inspection steps - 7680 port analysis - Dosvc service
(四)递归、可变参数、访问修饰符、理解 main 方法、代码块
Redis counts new and retained users
type_traits元编程库学习
[Swift] Customize the shortcut that pops up by clicking the APP icon
[Godot][GDScript] 2D cave map randomly generated
Component pass value provide/inject
The use of beforeDestroy and destroyed
Detailed explanation of TCP (1)
Mysql 45 study notes (twenty-five) MYSQL guarantees high availability
Mysql 45 study notes (twenty-four) MYSQL master-slave consistency
volatile内存语义以及实现 -volatile写和读对普通变量的影响
IIR filter and FIR filter
Learning DAVID Database (1)
Can‘t load /home/Iot/.rnd into RNG