input: 
  def Matrix(m: int, n: int, lst: List[float]) -> 'Matrix':
      """
      Develop a class in Python to perform various matrix operations like addition, 
      subtraction, multiplication and transpose.
      
      >>> Matrix(2, 2, [1, 2, 3, 4]).add(Matrix(2, 2, [5, 6, 7, 8]))
      6.0 8.0 
      10.0 12.0
      
      >>> Matrix(2, 2, [1, 2, 3, 4]).sub(Matrix(2, 2, [1, 1, 1, 1]))
      0.0 1.0
      2.0 3.0
      
      >>> Matrix(2, 2, [1, 2, 3, 4]).mul(Matrix(2, 2, [5, 6, 7, 8]))
      19.0 22.0
      43.0 50.0
      
      >>> Matrix(2, 2, [1, 2, 3, 4]).transpose()
      1.0 3.0
      2.0 4.0
      """
  
output:     
      class Matrix:
          def __init__(self, m: int, n: int, lst: List[float]):
              self.rows = m
              self.cols = n
              self.data = lst
          
          def add(self, other: 'Matrix') -> 'Matrix':
              if self.rows != other.rows or self.cols != other.cols:
                  raise ValueError("Matrices must have the same dimensions for addition.")
              result = [self.data[i] + other.data[i] for i in range(len(self.data))]
              return Matrix(self.rows, self.cols, result)
          
          def sub(self, other: 'Matrix') -> 'Matrix':
              if self.rows != other.rows or self.cols != other.cols:
                  raise ValueError("Matrices must have the same dimensions for subtraction.")
              result = [self.data[i] - other.data[i] for i in range(len(self.data))]
              return Matrix(self.rows, self.cols, result)
          
          def mul(self, other: 'Matrix') -> 'Matrix':
              if self.cols != other.rows:
                  raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix.")
              result = []
              for i in range(self.rows):
                  for j in range(other.cols):
                      sum = 0
                      for k in range(self.cols):
                          sum += self.data[i * self.cols + k] * other.data[k * other.cols + j]
                      result.append(sum)
              return Matrix(self.rows, other.cols, result)
          
          def transpose(self) -> 'Matrix':
              result = []
              for j in range(self.cols):
                  for i in range(self.rows):
                      result.append(self.data[i * self.cols + j])
              return Matrix(self.cols, self.rows, result)
          
          def __str__(self) -> str:
              return "\n".join([" ".join([str(self.data[i * self.cols + j]) for j in range(self.cols)]) for i in range(self.rows)])
  