Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions graphs_trees/graph/graph_challenge.ipynb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin) and [Kevin Chan](https://github.com/kevinxchan). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
@@ -145,11 +145,11 @@
" # TODO: Implement me\n",
" pass\n",
"\n",
" def add_edge(self, source, dest, weight=0):\n",
" def add_edge(self, source_key, dest_key, weight=0):\n",
" # TODO: Implement me\n",
" pass\n",
"\n",
" def add_undirected_edge(self, source, dest, weight=0):\n",
" def add_undirected_edge(self, source_key, dest_key, weight=0):\n",
" # TODO: Implement me\n",
" pass"
]
50 changes: 13 additions & 37 deletions graphs_trees/graph/graph_solution.ipynb
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
"This notebook was prepared by [Donne Martin](https://github.com/donnemartin) and [Kevin Chan](https://github.com/kevinxchan). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
]
},
{
@@ -153,19 +153,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting graph.py\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%writefile graph.py\n",
"from enum import Enum # Python 2 users: Run pip install enum34\n",
@@ -231,19 +221,17 @@
" self.add_node(dest_key)\n",
" self.nodes[source_key].add_neighbor(self.nodes[dest_key], weight)\n",
"\n",
" def add_undirected_edge(self, src_key, dst_key, weight=0):\n",
" def add_undirected_edge(self, source_key, dest_key, weight=0):\n",
" if src_key is None or dst_key is None:\n",
" raise TypeError('key cannot be None')\n",
" self.add_edge(src_key, dst_key, weight)\n",
" self.add_edge(dst_key, src_key, weight)"
" self.add_edge(source_key, dest_key, weight)\n",
" self.add_edge(dest_key, source_key, weight)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%run graph.py"
@@ -258,19 +246,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting test_graph.py\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%writefile test_graph.py\n",
"from nose.tools import assert_equal\n",
@@ -351,9 +329,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
@@ -389,5 +365,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}