看板 Python 關於我們 聯絡資訊
例如 2、11、1 請問大家是怎麼排序成1、2、11,而非1、11、2? 單純用sorted函數會排成1、11、2 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 205.185.209.31 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1597148828.A.23B.html
pmove: 轉成int再排?08/11 20:59
這是一個方法,但如果是文字和數字混合的話呢?
pmove: 原po是要問big integer的情況嗎?08/11 21:04
單純想看看大家怎麼做而已。 ※ 編輯: shala (205.185.209.31 美國), 08/11/2020 21:11:04
papple23g: sorted(List, key = lambda x: (len(x),x)) 08/11 21:32
TitanEric: 統一轉數字再sort 08/11 22:26
TuCH: 文字跟數字你要怎麼排? 08/12 08:11
TuCH: 1>2>99999>a>b>c>d>....>z? 08/12 08:12
annheilong: 參考:https://docs.python.org/3/howto/sorting.html 08/12 11:15
jigfopsda: sorted 可以自己寫比大小的 function 愛怎麼排就怎麼排 08/12 12:01
shala: 謝謝大家提供參考~ 08/12 18:30