Python中List的排序問題

來源:互聯網
上載者:User

標籤:python   www   list   排列   順序   結果   問題   style   put   

今天在知乎上看到一個文章  【Python中如何把兩個list合并,並按從小到大順序排列?】,試著解了一下。

 

記錄如下  以備以後察看

 

list1 = [12,33,190,29,15,9,28]list2 = [21,346,11]list3 = list1 + list2   #  列表合并 ==> 直接相加即可list_output = []   #  建立空列表while list3:  #  迴圈直到list3為空白    int_min = list3.pop(list3.index(min(list3)))   #   將最小值賦值給int_min    list_output.append(int_min)   #  將最小值依次傳入int_min列表中print list_output   #  驗證結果  [9, 11, 12, 15, 21, 28, 29, 33, 190, 346]

 

Python中List的排序問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.