finshed challenge notebook

This commit is contained in:
wdonahoe 2015-07-09 09:04:37 -04:00
parent 8c23acd55a
commit 84ca16fbb5

View File

@ -70,15 +70,37 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": { "metadata": {
"collapsed": false "collapsed": false
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"def make_order_list(list_in):\n",
" order_list = []\n",
" for item in list_in:\n",
" if item not in order_list:\n",
" order_list.append(item)\n",
" return order_list\n",
"\n",
"def group_ordered(list_in):\n", "def group_ordered(list_in):\n",
" # TODO: Implement me\n", " if list_in is None:\n",
" pass" " return None\n",
" order_list = make_order_list(list_in)\n",
" current = 0\n",
" for item in order_list:\n",
" search = current + 1\n",
" while True:\n",
" try:\n",
" if list_in[search] != item:\n",
" search += 1\n",
" else:\n",
" current += 1\n",
" list_in[current], list_in[search] = list_in[search], list_in[current]\n",
" search += 1\n",
" except IndexError:\n",
" break\n",
" return list_in"
] ]
}, },
{ {
@ -97,13 +119,41 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"metadata": { "metadata": {
"collapsed": false "collapsed": false
}, },
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Success: test_foo\n"
]
}
],
"source": [ "source": [
"%load test_group_ordered.py" "# %load test_group_ordered.py\n",
"from nose.tools import assert_equal\n",
"\n",
"class TestFoo(object):\n",
"\n",
" def test_foo(self):\n",
" assert_equal(group_ordered(None), None)\n",
" assert_equal(group_ordered([]), [])\n",
" assert_equal(group_ordered([1]), [1])\n",
" assert_equal(group_ordered([1,2,1,3,2]),[1,1,2,2,3])\n",
" assert_equal(group_ordered(['a','b','a']),['a','a','b'])\n",
" assert_equal(group_ordered([1,1,2,3,4,5,2,1]),[1,1,1,2,2,3,4,5])\n",
" assert_equal(group_ordered([1,2,3,4,3,4]),[1,2,3,3,4,4])\n",
" print('Success: test_foo')\n",
"\n",
"def main():\n",
" test = TestFoo()\n",
" test.test_foo()\n",
"\n",
"if __name__ == '__main__':\n",
" main()\n"
] ]
}, },
{ {