Skip to content

Commit

Permalink
matrices v1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Oct 10, 2018
1 parent c806750 commit 2335d04
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions exercises/matrices/matrices-solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,53 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### WORK IN PROGRESS"
"### Matrices as lists of lists"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# SOLUTION"
"\n",
"def stitch_right(mat1,mat2):\n",
" \"\"\"Given matrices as list of lists mat1 of size n x l and mat2 of size n x r \n",
" RETURN a NEW matrix of size n x (l + r) as list of lists, by stitching second mat to the right end of mat1\n",
" \"\"\"\n",
" #jupman-raise\n",
" ret = []\n",
" for i in range(len(mat1)):\n",
" row_to_add = mat1[i][:]\n",
" row_to_add.extend(mat2[i])\n",
" ret.append(row_to_add)\n",
" return ret\n",
" #/jupman-raise\n",
" \n",
"m1 = [[]]\n",
"m2 = [[]]\n",
"assert stitch_right(m1, m2) == [[]]\n",
"\n",
"m1 = [\n",
" ['a','b','c'],\n",
" ['d','b','a']\n",
" ]\n",
"m2 = [\n",
" [ 'f','b'],\n",
" ['g','h']\n",
" ]\n",
"\n",
"res = [\n",
" ['a','b','c','f','b'],\n",
" ['d','b','a','g','h']\n",
" ]\n",
"\n",
"assert stitch_right(m1, m2) == res"
]
},
{
Expand Down

0 comments on commit 2335d04

Please sign in to comment.