Coding/Python Matlab

파이썬 - multi-column data array (list) sorting

smores 2012. 2. 24. 04:27
>>> dist = [[25, 1],                                                                                                                                                                                               
            [12, 2],                                                                                                                                                                                                   
            [11, 3]]
... ... >>> 
>>> dist.sort(key=lambda a: a[0]) # key function only looks at first element in row ie column 0
>>> dist
[[11, 3], [12, 2], [25, 1]]
>>> dist = dist[0:2]  # take only the first 2 rows
>>> dist
[[11, 3], [12, 2]]

'Coding > Python Matlab' 카테고리의 다른 글

파이썬 - python 2.7 print function usage  (0) 2012.10.10
파이썬 - 웹 링크 다운로드 (버퍼)  (0) 2012.03.13
파이썬 - SciPy, NumPy  (2) 2012.02.23
파이썬 - 만화 다운로드  (0) 2012.02.14
파이썬 - wxPython  (0) 2012.01.29