(创建一个列表a)(创建一个列表,其中包含一系列简短的文本消息)

(创建一个列表a)(创建一个列表,其中包含一系列简短的文本消息)

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard学苑。今天小编为大家带来“学习知多少(python篇):列表的操作与应用”,欢迎您的访问。

Share interests, spread happiness, increase knowledge, and leave a good legacy!

Dear you, this is The LearningYard Academy. Today Xiaobian brings you "Learn how much to know (python):Actions and applications of lists”, welcome your visit.

目的:学习列表的操作与应用,例如合并两个列表并去重、对列表元素进行分类后加标签入字典、列表反转、列表元素绝对值排序等,掌握如何对列表进行创建、删除和修改。

Objective: To learn the operation and application of lists, such as merging two lists and deduplication, classifying list elements and adding tags to the dictionary, list inversion, ranking absolute values of list elements, etc., and mastering how to create, delete and modify lists.

1、合并两个列表并去重可以先创建两个新列表,使用以下实现列表alist的创建:Alist=list(map(int,input().split()))然后将两个新列表相加形成新的列表,通过set集合进行去重,最后用sorted内置函数将新的列表进行排序并打印出来。

(创建一个列表a)(创建一个列表,其中包含一系列简短的文本消息)

1、Merge two lists and deduplicate can first create two new lists, use the following to implement the creation of list alist: Alist=list(map(int,input().split()))) and then add the two new lists to form a new list, deduplicate it through the set set, and finally use the sorted built-in function to sort and print out the new list.

2、对列表元素进行分类后加标签存入字典可以创建一个列表,用len()得出列表长度,通过切片,去除列表的前一半和后一半,再用构造字典的方法构造一个有两个key:‘1’‘2’的字典打印出来就完成了。

(创建一个列表a)(创建一个列表,其中包含一系列简短的文本消息)

2. After classifying the list elements and adding tags to the dictionary, you can create a list, use len() to get the list length, remove the first half and the last half of the list by slicing, and then use the method of constructing a dictionary to construct a dictionary with two keys: '1' and '2' and print it out.

今天的分享就到这里了。
如果您对今天的文章有独特的想法,
欢迎给我们留言,
让我们相约明天。
祝您今天过得开心快乐!

That's all for today's sharing.
If you have a unique idea for today’s article,
please leave us a message,
and let us meet tomorrow.
I wish you a happy day !

本文由learningyard新学苑原创,如有侵权,请联系我们!

翻译来源于谷歌翻译

部分来源于

百度文库

清华大学出版 董付国《Python程序设计基础》

编辑&排版|百味

审核|闫庆红

声明:我要去上班所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,版权归原作者LearningYard学苑所有,原文出处。若您的权利被侵害,请联系删除。

本文标题:(创建一个列表a)(创建一个列表,其中包含一系列简短的文本消息)
本文链接:https://www.51qsb.cn/article/m7067.html

(0)
打赏微信扫一扫微信扫一扫QQ扫一扫QQ扫一扫
上一篇2022-12-09
下一篇2022-12-09

你可能还想知道

发表回复

登录后才能评论