      "class MyLinkedList(LinkedList):\n",
      "    def kth_to_last_elem(self, k):\n",
      "        if self.head is None:\n",
      "            return\n",
      "        if type(k) != int:\n",
      "            raise ValueError('')\n",
      "        if k >= len(self):\n",
      "            return\n",
      "        curr = self.head\n",
      "        prev = self.head\n",
      "        counter = 0\n",
 
</s> remove     "# Empty list\n",
    "linked_list = MyLinkedList(None)\n",
    "print(linked_list.kth_to_last_elem(0))\n",
    "# k is not an integer\n",
    "print(linked_list.kth_to_last_elem('a'))\n",
    "# k is >= the length of the linked list\n",
    "print(linked_list.kth_to_last_elem(100))\n",
    "# One element, k = 0\n",
    "head = Node(2)\n",
    "linked_list = MyLinkedList(head)\n",
    "print(linked_list.kth_to_last_elem(0))\n",
    "# General case with many elements, k < length of linked list\n",
    "linked_list.insert_to_front(1)\n",
    "linked_list.insert_to_front(3)\n",
    "linked_list.insert_to_front(5)\n",
    "linked_list.insert_to_front(7)\n",
    "print(linked_list.kth_to_last_elem(2))"
 </s> add     "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_kth_to_last_elem(self):\n",
    "        print('Test: Empty list')\n",
    "        linked_list = MyLinkedList(None)\n",
    "        assert_equal(linked_list.kth_to_last_elem(0), None)\n",
    "        \n",
    "        print('Test: k >= len(list)')\n",
    "        assert_equal(linked_list.kth_to_last_elem(100), None)\n",
    "        \n",
    "        print('Test: One element, k = 0')\n",
    "        head = Node(2)\n",
    "        linked_list = MyLinkedList(head)\n",
    "        assert_equal(linked_list.kth_to_last_elem(0), 2)\n",
    "        \n",
    "        print('Test: General case')\n",
    "        linked_list.insert_to_front(1)\n",
    "        linked_list.insert_to_front(3)\n",
    "        linked_list.insert_to_front(5)\n",
    "        linked_list.insert_to_front(7)\n",
    "        assert_equal(linked_list.kth_to_last_elem(2), 3)\n",
    "        \n",
    "        print('Success: test_kth_to_last_elem')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    test = Test()\n",
    "    test.test_kth_to_last_elem()" </s> remove     "    * No"
 </s> add     "    * No\n",
    "* Can we assume we already have a linked list class that can be used for this problem?\n",
    "    * Yes" </s> remove     "* Is k an integer?\n",
 </s> add     "*Problem statements are often intentionally ambiguous.  Identifying constraints and stating assumptions can help to ensure you code the intended solution.*\n",
    "\n",
    "* Can we assume k is a valid integer?\n",
      "class MyLinkedList(LinkedList):\n",
      "    def kth_to_last_elem(self, k):\n",
      "        if self.head is None:\n",
      "            return\n",


      "        if k >= len(self):\n",
      "            return\n",
      "        curr = self.head\n",
      "        prev = self.head\n",
      "        counter = 0\n",
keep keep keep keep replace replace keep keep keep keep keep
 Reworked notebook: Added more detail to constraints and test cases.  Reworked code and unit test. 
linked-lists/kth-to-last-elem.ipynb