def sort(self, cmp=None, key=None, reverse=False):
    """Sorts rows in the texttable.

    Args:
      cmp: func, non default sort algorithm to use.
      key: func, applied to each element before sorting.
      reverse: bool, reverse order of sort.
    """

    def _DefaultKey(value):
      """Default key func is to create a list of all fields."""
      result = []
      for key in self.header:
        # Try sorting as numerical value if possible.
        try:
          result.append(float(value[key]))
        except ValueError:
          result.append(value[key])
      return result

    key = key or _DefaultKey
    # Exclude header by copying table.
    new_table = self._table[1:]
    new_table.sort(cmp, key, reverse)
    # Regenerate the table with original header
    self._table = [self.header]
    self._table.extend(new_table)
    # Re-write the 'row' attribute of each row
    for index, row in enumerate(self._table):
      row.row = index
  # pylint: enable=W0622
dataset/ETHPy150Open google/textfsm/texttable.py/TextTable.sort/original