#NEWLINE# def sort( self , field = None , nums = False ) : #NEWLINE# #INDENT# ' sort by specified fields (see fields())\n\n        Example::\n            a.sort(1, nums = True)\n\n        Sorts a by second field, in numerical order (so that 21 > 3)\n\n        ' #NEWLINE# if ( field is not None ) : #NEWLINE# #INDENT# dsu = [ [ SList ( [ line ] ) . fields ( field ) , line ] for line in self ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dsu = [ [ line , t ] for line in self ] #NEWLINE# #UNINDENT# if nums : #NEWLINE# #INDENT# for i in range ( len ( dsu ) ) : #NEWLINE# #INDENT# numstr = '' . join ( [ ch for ch in dsu [ i ] [ 0 ] if ch . isdigit ( ) ] ) #NEWLINE# try : #NEWLINE# #INDENT# n = int ( numstr ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# n = 0 #NEWLINE# #UNINDENT# dsu [ i ] [ 0 ] = n #NEWLINE# #UNINDENT# #UNINDENT# dsu . sort ( ) #NEWLINE# return SList ( [ t [ 1 ] for t in dsu ] )