# Copyright (c) 2017 The Regents of the University of Michigan.
# All Rights Reserved. Licensed according to the terms of the Revised
# BSD License. See LICENSE.txt for details.

class Table:

    class InputStrContainsCarriageReturn (RuntimeError):
        pass

    def __init__ (self, tab_separated_text = None):
        self.text = tab_separated_text

        self.__raise_error_if_carriage_returns()
        self.__create_internal_structure()

    @property
    def rows (self):
        return len(self)

    @property
    def cols (self):
        return len(self.__rows[0]) if self else 0

    def __len__ (self):
        return len(self.__rows)

    def __iter__ (self):
        return iter(self.__rows)

    def __getitem__ (self, key):
        return self.__rows[key]

    def __repr__ (self):
        return "<{} {}>".format(self.__class__.__name__,
                                repr(self.text))

    def __raise_error_if_carriage_returns (self):
        if self.text and "\r" in self.text:
            raise self.InputStrContainsCarriageReturn

    def __create_internal_structure (self):
        if self.text:
            self.__rows = self.__list_of_rows_from_text()

        else:
            self.__rows = []

    def __list_of_rows_from_text (self):
        result = []
        rows = iter(self.__rows_from_text())
        result.append(self.__split_row(next(rows)))

        for row_text in rows:
            row = self.__split_row(row_text)

            if len(row) != len(result[0]):
                raise RuntimeError

            result.append(row)

        return result

    def __split_row (self, row_text):
        return tuple(row_text.split("\t"))

    def __rows_from_text (self):
        return self.text.rstrip("\n").split("\n")

@@ -1284,30 +1284,37 @@
  = %5B
-%5D%0A        rows = iter(
+self.__split_row(r) for r in 
 self
@@ -1332,17 +1332,18 @@
 m_text()
-)
+%5D%0A
 %0A       
@@ -1348,38 +1348,47 @@
    r
-esult.append(self.__spli
+ows = iter(result)%0A        firs
 t_row
-(
+ = 
 next
@@ -1393,19 +1393,16 @@
 xt(rows)
-))
-%0A
 %0A       
@@ -1409,21 +1409,16 @@
  for row
-_text
  in rows
@@ -1423,54 +1423,8 @@
 ws:%0A
-            row = self.__split_row(row_text)%0A%0A
     
@@ -1454,17 +1454,17 @@
 len(
-result%5B0%5D
+first_row
 ):%0A 
@@ -1502,40 +1502,8 @@
 or%0A%0A
-            result.append(row)%0A%0A
     

Use list comprehension; validate afterward