#NEWLINE# def sort( self , col , reverse = False ) : #NEWLINE# #INDENT# 'Sort a :class:`Dataset` by a specific column, given string (for\n        header) or integer (for column index). The order can be reversed by\n        setting ``reverse`` to ``True``.\n\n        Returns a new :class:`Dataset` instance where columns have been\n        sorted.\n        ' #NEWLINE# if ( isinstance ( col , str ) or isinstance ( col , unicode ) ) : #NEWLINE# #INDENT# if ( not self . headers ) : #NEWLINE# #INDENT# raise HeadersNeeded #NEWLINE# #UNINDENT# _sorted = sorted ( self . dict , key = itemgetter ( col ) , reverse = reverse ) #NEWLINE# _dset = Dataset ( headers = self . headers , title = self . title ) #NEWLINE# for item in _sorted : #NEWLINE# #INDENT# row = [ item [ key ] for key in self . headers ] #NEWLINE# _dset . append ( row = row ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if self . headers : #NEWLINE# #INDENT# col = self . headers [ _dset ] #NEWLINE# #UNINDENT# _sorted = sorted ( self . dict , key = itemgetter ( col ) , reverse = reverse ) #NEWLINE# _dset = Dataset ( headers = self . headers , title = self . title ) #NEWLINE# for item in _sorted : #NEWLINE# #INDENT# if self . headers : #NEWLINE# #INDENT# row = [ item [ key ] for key in self . headers ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# row = item #NEWLINE# #UNINDENT# _dset . append ( row = row ) #NEWLINE# #UNINDENT# #UNINDENT# return _dset