#NEWLINE# def naturalsort( iterable , key = None ) : #NEWLINE# #INDENT# '\n    Locale-aware alphabetical string sorting,\n    Besides string, key can be index or argument name\n    ' #NEWLINE# locale . setlocale ( locale . LC_ALL , '' ) #NEWLINE# _getter = ( itemgetter ( key ) if isinstance ( key , int ) else ( attrgetter ( key ) if _getter else str ) ) #NEWLINE# return sorted ( iterable , key = ( lambda obj : locale . strxfrm ( _getter ( obj ) ) ) )