当前位置:网站首页>问题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]
边栏推荐
- Observer pattern
- (4) Recursion, variable parameters, access modifiers, understanding main method, code block
- [Paper reading] Mastering the game of Go with deep neural networks and tree search
- The els block moves the boundary to the right, and accelerates downward.
- Select the smoke test case, and make the first pass for the product package entering QA
- (六)枚举、注解
- $parent/$children and ref
- Component pass value provide/inject
- [C language] Three-pointed chess (classic solution + list diagram)
- How to develop a high-quality test case?
猜你喜欢

识Flutter 基本组件之showTimePicker 方法

C语言从入门到如土——数据的存储

Knowledge Distillation 7: Detailed Explanation of Knowledge Distillation Code

Ambiguous method call.both

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

Learning DAVID Database (1)

SIP Protocol Standard and Implementation Mechanism

postgresql 15源码浅析(5)—— pg_control

Detailed explanation of TCP and UDP
![Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]](/img/83/e0163b324448c6ef5b106862673637.jpg)
Summary of Huawei Distributed Storage FusionStorage Knowledge Points [Interview]
随机推荐
STM32 problem collection
Based on the local, linking the world | Schneider Electric "Industrial SI Alliance" joins hands with partners to go to the future industry
Daily practice of LeetCode - palindrome structure of OR36 linked list
type_traits metaprogramming library learning
自己的一些思考
(树) 最近公共祖先(LCA)
慧通编程第4关 - 魔法学院第6课
The use of beforeDestroy and destroyed
some of my own thoughts
Redis counts new and retained users
Safety 20220712
(8) Math class, Arrays class, System class, Biglnteger and BigDecimal classes, date class
els 方块向右移
No qualifying bean of type question
$attrs/$listeners
Safety 20220715
IDEA common shortcut keys and plug-ins
(Line segment tree) Summary of common problems of basic line segment tree
els 方块向右移动边界判断、向下加速
安全20220712