Last active
February 21, 2020 06:41
-
-
Save patternproject/ea40414d2bf4b916eb3efdbab4a3a839 to your computer and use it in GitHub Desktop.
Untitled0.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Untitled0.ipynb", | |
"provenance": [], | |
"authorship_tag": "ABX9TyNIeXpF+9F0iXhWcF1vkTC9", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/patternproject/ea40414d2bf4b916eb3efdbab4a3a839/untitled0.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IpSgp6g0eSqZ", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# implementing without built-in sort function\n", | |
"\n", | |
"def linear_merge2(l1,l2):\n", | |
" \"\"\"Merges the two input list and then returns a combined sorted list\"\"\"\n", | |
" \n", | |
" print(\"first list\")\n", | |
" print(l1)\n", | |
" #print(\"\\n\")\n", | |
" print(\"second list\")\n", | |
" print(l2)\n", | |
" #print(\"\\n\")\n", | |
"\n", | |
"\n", | |
" l_merged = []\n", | |
"\n", | |
" for e in l1:\n", | |
" print(\"outer loop with e equal to\")\n", | |
" print(e)\n", | |
" for m in l2:\n", | |
" print(\"inner loop with m equal to\")\n", | |
" print(m)\n", | |
" if e < m:\n", | |
" l_merged.append(e)\n", | |
" print(\"if branch\")\n", | |
" print(\"----------------\")\n", | |
" print(\"l_merged\")\n", | |
" print(l_merged)\n", | |
" print(\"\\n\")\n", | |
" break\n", | |
" \n", | |
" elif e >= m:\n", | |
" l_merged.append(m)\n", | |
" print(\"else branch\")\n", | |
" print(\"----------------\")\n", | |
" print(\"l_merged\")\n", | |
" print(l_merged)\n", | |
" print(\"\\n\")\n", | |
" \n", | |
" l2.remove(m)\n", | |
" print(\"removed l2\")\n", | |
" print(l2)\n", | |
" print(\"\\n\")\n", | |
"\n", | |
" print(\"out of for loop\")\n", | |
" print(l_merged)\n", | |
" print(\"\\n\")\n", | |
"\n", | |
" if len(l2) > 0:\n", | |
" l_merged.extend(l2)\n", | |
"\n", | |
" print(\"after final if \")\n", | |
" print(l_merged)\n", | |
"\n", | |
" print(\"exiting function\")\n", | |
" return(l_merged)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment