【程式碼題python】:一個列表[1,2,5,3,2,5,7,8,9,11,2,33,44,51,4,7,9],請去除重複數字並輸出去除後新的列表
題目
一個列表[1,2,5,3,2,5,7,8,9,11,2,33,44,51,4,7,9],請去除重複數字並輸出去除後新的列表
程式碼
list1 = [1, 2, 5, 3, 2, 5, 7, 8, 9, 11, 2, 33, 44, 51, 4, 7, 9]
print(f'原始列表為:{list1}')
list2 = []
for i in range(len(list1)):
if list1[i] in list1[0:i]:
list2.append(list1[i])
for j in list2:
list1. remove(j)
print(f'去除重複數字後的列表為:{list1}')
結果
相關推薦
【程式碼題python】:一個列表[1,2,5,3,2,5,7,8,9,11,2,33,44,51,4,7,9],請去除重複數字並輸出去除後新的列表
技術標籤:pythonpython 題目 一個列表[1,2,5,3,2,5,7,8,9,11,2,33,44,51,4,7,9],請去除重複數字並輸出去除後新的列表 程式碼
【程式碼題python】:將n元錢隨機分給m個人,每個人最少0.01。輸入m、n,輸出長度為m的陣列。
技術標籤:pythonpython 題目 將n元錢隨機分給m個人,每個人最少0.01。輸入m、n,輸出長度為m的陣列。例如輸入10.00,2,輸出[8.17,1.83]
【程式碼題python】【leetcode】:最長迴文串
技術標籤:pythonleetcodepython 題目 給定一個字串 s,找到 s 中最長的迴文子串 迴文串示例:abcba 給定字串:sssabcba1da
【程式碼題python】【leetcode】找到字串的最長無重複字元子串
技術標籤:python演算法pythonleetcode 參考:https://blog.csdn.net/qq_34771726/article/details/88643476 給定一個數組arr,返回arr的最長無的重複子串的長度(無重複指的是所有數字都不相同)。 示例一示例二程
【刷題-LeetCode】191 Number of 1 Bits
Number of 1 Bits Write a function that takes an unsigned integer and return the number of \'1\' bits it has (also known as the Hamming weight).
VUE移動端音樂APP學習【二十五】:歌曲列表元件開發(二)
實現點選垃圾桶,清除所有歌曲列表功能 和之前清除所有搜尋歷史列表一樣,引用confirm元件攔截提示使用者的操作
基類使用私有資料_【進階Python】第七講:介面與抽象基類
技術標籤:基類使用私有資料怎麼檢視抽象方法被哪些類繼承 點選藍字關注我
for 迴圈語句基本用法及示例_【文山玩Python】迴圈語句:用for語句迴圈一切可遍歷物件...
技術標籤:for 迴圈語句基本用法及示例 for in不僅可以使用range()函式來產生多次迴圈,也可以用來迴圈其它資料型別,比如用for來迴圈字串:
【尋找單身狗】:有一組資料,只有一個數字是出現一次,其他是兩次,請找出這個數字。
技術標籤:java語法練習 public class Test { public static void main(String[] args) { int arr[]={1,2,3,4,5,4,3,2,1};
【經典面試題】給定一個由 n 個整陣列成的陣列 list,在 list 中是否有元素 a, b, c 這樣的 a + b + c = 0?找出陣列中所有唯一的三元組,得出總和等於0 注:得到的解集不能包含重複的三元組。
# conding:utf8# author:mylittlegoblinimport pytestclass Three_list():def three_list(self, nums):res = []nums.sort()# 首先機進行大小排序for index_x in range(0, len(nums) - 2):# len(nums)-2 避免重複計算
我的物聯網大學【第八章】:跟一個女採購見光死的故事
一個女採購,計劃匯入我們的Air202模組,開發報警器產品,大概一年有個10萬片的模組需求。
Linux從頭學06:16張結構圖,徹底理解【程式碼重定位】的底層原理
作者:道哥,10+年的嵌入式開發老兵。 公眾號:【IOT物聯網小鎮】,專注於:C/C++、Linux作業系統、應用程式設計、物聯網、微控制器和嵌入式開發等領域。公眾號回覆【書籍】,獲取 Linux、嵌入式領域經典書籍。
【PTA|Python】浙大版《Python 程式設計》題目集:第二章
前言 Hello!小夥伴! 非常感謝您閱讀海轟的文章,倘若文中有錯誤的地方,歡迎您指出~
【網路爬蟲學習】第一個Python爬蟲程式 & 編碼與解碼詳解 & Pythonの實現
本節編寫一個最簡單的爬蟲程式,作為學習 Python 爬蟲前的開胃小菜。 下面使用 Python 內建的 urllib 庫獲取網頁的 html 資訊。注意,urllib 庫屬於 Python 的標準庫模組,無須單獨安裝,它是 Python 爬蟲的常用模組
【華為OD機試真題 python】日誌首次上報最多積分【2022 Q4 | 100分】
Override the entrypoint of an image Introduced in GitLab and GitLab Runner 9.4. Read more about the extended configuration options.
【刷題-LeetCode】165 Compare Version Numbers
Compare Version Numbers Compare two version numbers version1 and version2. If *version1* > *version2* return 1; if *version1* < *version2* return -1;otherwise return 0.
【刷題-LeetCode】179 Largest Number
Largest Number Given a list of non negative integers, arrange them such that they form the largest number.
【刷題-LeetCode】122 Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i.
【刷題-LeetCode】123 Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the price of a given stock on day i.
【刷題-LeetCode】199 Binary Tree Right Side View
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.