<address id="zhpbl"></address>
<noframes id="zhpbl">
<address id="zhpbl"><form id="zhpbl"><th id="zhpbl"></th></form></address>

    <em id="zhpbl"></em>

      <address id="zhpbl"><th id="zhpbl"><progress id="zhpbl"></progress></th></address>
      更多精彩內容,歡迎關注:

      視頻號
      視頻號

      抖音
      抖音

      快手
      快手

      微博
      微博

      python中sorted函數的用法

      文檔

      python中sorted函數的用法

      sorted用法為sorted(iterable,cmp=None,key=None,reverse=False),iterable指可迭代的對象,cmp指比較函數,key指用列表元素的某個屬性或函數作為關鍵字,reverse指排序規則。
      推薦度:
      導讀sorted用法為sorted(iterable,cmp=None,key=None,reverse=False),iterable指可迭代的對象,cmp指比較函數,key指用列表元素的某個屬性或函數作為關鍵字,reverse指排序規則。

      python中sorted函數的用法是什么?一起來看看小編今天的分享吧!

      sorted用法:sorted(iterable,cmp=None,key=None,reverse=False)

      其中iterable指可迭代的對象;

      cmp指比較函數,比較什么由參數key決定;例如:cmp(e1, e2) 是具有兩個參數的比較函數,返回值:負數(e1 < e2);0(e1 == e2);正數( e1 > e2)。

      key指用列表元素的某個屬性或函數作為關鍵字;

      reverse指排序規則,reverse=True降序,reverse=False升序(默認)。

      例如:

      >>>?a_dict={'A':2,'B':3,'C':4,'D':1,'E':5}
      >>>?sorted_a_dict?=?sorted(a_dict.items(),?key?=?lambda?x:x[1],?reverse?=?True)
      >>>?sorted_a_dict
      [('E',?5),?('C',?4),?('B',?3),?('A',?2),?('D',?1)]

      表示sorted() 函數對所有可迭代的對象進行排序操作,返回重新排序的列表;items() 方法以列表返回可遍歷的(鍵, 值) 元組數組;?lambda 構造匿名函數,以元組中第二個元素作為排序依據,即x[1];?reverse = True 表示降序排列;?最后得到的 word_freq_dict 為按照頻率倒敘排列的 (鍵, 值)元組的列表。

      以上就是小編今天的分享了,希望可以幫助到大家。

      文檔

      python中sorted函數的用法

      sorted用法為sorted(iterable,cmp=None,key=None,reverse=False),iterable指可迭代的對象,cmp指比較函數,key指用列表元素的某個屬性或函數作為關鍵字,reverse指排序規則。
      推薦度:
      為你推薦
      資訊專欄
      熱門視頻
      相關推薦
      mysql time類型 js class類 python中strip函數的用法 getclass方法 python中find函數的用法 java反射獲取屬性值 vue 調用子組件方法 python的range函數用法 js set去重 vue使用jquery python skimage armoury crate打不開 java process deque java linux 格式化u盤 js讀取文件 python 交集 object 轉list object轉bigdecimal java get和set方法 cad的基本命令 ubuntu卸載mysql js獲取隨機數 opencv安裝教程python python numpy教程 js獲取日期 python tkinter教程 java reentrantlock c語言struct用法 字符轉換成ascii碼 js date加一天 vue動態綁定style spring boot mysql配置 python 排序算法 python字典按值的大小排序 python 列表添加 python讀取json并解析 debug error怎么解決 python延時函數 python構造函數
      Top 少妇高潮太爽了在线视频