当前位置:网站首页>问题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]
边栏推荐
- [Dynamic programming] Maximum sum of consecutive subarrays
- C primer plus study notes - 8, structure
- 【论文阅读】Mastering the game of Go with deep neural networks and tree search
- Key Technologies of Interface Testing
- (线段树) 基础线段树常见问题总结
- Day32 LeetCode
- Analysis summary - self-use
- 识Flutter 基本组件之showTimePicker 方法
- Zotero如何删除自动生成的标签
- (四)递归、可变参数、访问修饰符、理解 main 方法、代码块
猜你喜欢
postgresql 15源码浅析(5)—— pg_control
[C language] General method of expression evaluation
浅识Flutter 基本组件之CheckboxListTile组件
[Paper reading] Mastering the game of Go with deep neural networks and tree search
SIP Protocol Standard and Implementation Mechanism
Daily practice of LeetCode - palindrome structure of OR36 linked list
Based on the local, linking the world | Schneider Electric "Industrial SI Alliance" joins hands with partners to go to the future industry
Database implements distributed locks
LocalDate addition and subtraction operations and comparison size
No qualifying bean of type question
随机推荐
[Paper reading] Mastering the game of Go with deep neural networks and tree search
Select the smoke test case, and make the first pass for the product package entering QA
Point Cloud DBSCAN Clustering (MATLAB, not built-in function)
Why don't you programmers make a living off your own projects?And have to work for someone else?
Web container and IIS --- Middleware penetration method 1
Understanding and Using Unity2D Custom Scriptable Tiles (4) - Start to build a custom tile based on the Tile class (below)
VS QT - ui does not display newly added members (controls) || code is silent
LeetCode simple problem to find the subsequence of length K with the largest sum
Zotero如何删除自动生成的标签
Pytest电商项目实战(上)
日志级别 和 打印log注意
type_traits metaprogramming library learning
some of my own thoughts
Redis implements distributed locks
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
自己的一些思考
(tree) Last Common Ancestor (LCA)
$parent/$children and ref
【CocosCreator 3.5】CocosCreator get network status
IDEA常用快捷键与插件