def _sort_messages(messages, sort_by):
 messages = list(messages)
 if (sort_by == 'message'):
  messages.sort()
 elif (sort_by == 'location'):
  messages.sort(key=(lambda m: m.locations))
 return messages

def _sort_messages ( messages , sort_by ) : messages = list ( messages ) if ( sort_by == 'message' ) : messages . sort ( ) elif ( sort_by == 'location' ) : messages . sort ( key = ( lambda m : m . locations ) ) return messages
sort the given message iterable by the given criteria .