     "source": [
      "from __future__ import division\n",
      "\n",
      "\n",
      "def merge(left, right):\n",
      "    l = 0\n",
      "    r = 0\n",
      "    result = []\n",
      "    while l < len(left) and r < len(right):\n",
      "        if left[l] < right[r]:\n",
      "            result.append(left[l])\n",
      "            l += 1\n",
      "        else:\n",
      "            result.append(right[r])\n",
      "            r += 1\n",
 
</s> remove     "        else:\n",
 </s> add     "        while r < len(right):\n", </s> remove     "            \n",
    "    # Copy remaining elements\n",
    "    while l < len(left):\n",
    "        result.append(left[l])\n",
    "        l += 1\n",
    "    while r < len(right):\n",
    "        result.append(right[r])\n",
    "        r += 1\n",
    "    return result\n",
    "\n",
    "\n",
    "def merge_sort(data):\n",
    "    if data is None or len(data) < 2:\n",
    "        return data\n",
    "    mid = len(data) // 2\n",
    "    left = data[:mid]\n",
    "    right = data[mid:]\n",
    "    left = merge_sort(left)\n",
    "    right = merge_sort(right)\n",
    "    return merge(left, right)"
 </s> add     "        return result" </s> remove     "from nose.tools import assert_equal\n",
 </s> add     "from nose.tools import assert_equal, assert_raises\n", </s> remove     "from nose.tools import assert_equal\n",
 </s> add     "from nose.tools import assert_equal, assert_raises\n", </s> remove     "        data = []\n",
    "        sorted_data = merge_sort(data)\n",
    "        assert_equal(sorted_data, [])\n",
 </s> add     "        assert_equal(merge_sort.sort([]), [])\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
     "source": [
      "from __future__ import division\n",
      "\n",
      "\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
    "class MergeSort(object):\n",
    "\n",
    "    def sort(self, data):\n",
    "        if data is None:\n",
    "            raise TypeError('data cannot be None')\n",
    "        return self._sort(data)\n",
    "\n",
    "    def _sort(self, data):\n",
    "        if len(data) < 2:\n",
    "            return data\n",
    "        mid = len(data) // 2\n",
    "        left = data[:mid]\n",
    "        right = data[mid:]\n",
    "        left = self._sort(left)\n",
    "        right = self._sort(right)\n",
    "        return self._merge(left, right)\n",
    "\n",
    "    def _merge(self, left, right):\n",
    "        l = 0\n",
    "        r = 0\n",
    "        result = []\n",
    "        while l < len(left) and r < len(right):\n",
    "            if left[l] < right[r]:\n",
    "                result.append(left[l])\n",
    "                l += 1\n",
    "            else:\n",
    "                result.append(right[r])\n",
    "                r += 1\n",
    "        # Copy remaining elements\n",
    "        while l < len(left):\n",
      "            result.append(left[l])\n",
      "            l += 1\n",
      "        else:\n",
      "            result.append(right[r])\n",
      "            r += 1\n",
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
 Update merge sort challenge (#130)

Update constraints, test cases, code, and tests. 
sorting_searching/merge_sort/merge_sort_solution.ipynb