您現在的位置是:首頁 > 遊戲

學習知多少(python篇):列表的操作與應用

由 LearningYard學苑 發表于 遊戲2023-01-05
簡介今天小編為大家帶來“學習知多少(python篇):列表的操作與應用”,歡迎您的訪問

計算機語言設定在哪裡

學習知多少(python篇):列表的操作與應用

學習知多少(python篇):列表的操作與應用

學習知多少(python篇):列表的操作與應用

01:22

未知來源

分享興趣,傳播快樂,增長見聞,留下美好!

親愛的您,這裡是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內建函式將新的列表進行排序並打印出來。

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’的字典打印出來就完成了。

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程式設計基礎》

編輯&排版|百味

稽核|閆慶紅

推薦文章