Colorful Life2010

日归档: 2006年04月03日 | 记录数: 1
Python下为字典排序
Weather:阴 ,东南风 4-5级 ,最低气温4 ℃

<p># (IMHO) the simplest approach:<br /> def sortedDictValues1(adict):<br /> &nbsp;&nbsp;&nbsp; items = adict.items()<br /> &nbsp;&nbsp;&nbsp; items.sort()<br /> &nbsp;&nbsp;&nbsp; return [value for key, value in items]<br /> <br /> # an alternative implementation, which<br /> # happens to run a bit faster for large<br /> # dictionaries on my machine:<br /> def sortedDictValues2(adict):<br /> &nbsp;&nbsp;&nbsp;...</p>