{
"metadata": {
"name": "",
"signature": "sha256:0b45935af8c2775c07e2411f97855bbf8ef699545a4925f6f3b744dc6790608b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"class ListTable(list):\n",
" \"\"\" Overridden list class which takes a 2-dimensional list of the form [[1,2,3],[4,5,6]]\n",
" and renders an HTML Table in IPython Notebook. \"\"\"\n",
" \n",
" def _repr_html_(self):\n",
" html = [\"
\"]\n",
" for row in self:\n",
" html.append(\"\")\n",
" \n",
" for col in row:\n",
" html.append(\"{0} | \".format(col))\n",
" \n",
" html.append(\"
\")\n",
" html.append(\"
\")\n",
" return ''.join(html)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import random\n",
"table = ListTable()\n",
"table.append(['x', 'y', 'x-y', '(x-y)^2'])\n",
"for i in xrange(7):\n",
" x = random.uniform(0, 10)\n",
" y = random.uniform(0, 10)\n",
" table.append([x, y, x-y, (x-y)**2])\n",
"table"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"x | y | x-y | (x-y)^2 |
8.90990894092 | 2.73708114406 | 6.17282779687 | 38.1038030097 |
8.37939022286 | 2.89965549177 | 5.47973473109 | 30.0274927231 |
1.9603923777 | 1.58915711179 | 0.371235265914 | 0.137815622658 |
5.29883233292 | 2.60058684074 | 2.69824549218 | 7.2805287361 |
6.25154987151 | 8.92385633612 | -2.67230646461 | 7.1412218408 |
3.87441580408 | 3.62080255925 | 0.253613244835 | 0.064319677956 |
1.69084608687 | 5.99836905642 | -4.30752296955 | 18.5547541332 |
"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": [
"[['x', 'y', 'x-y', '(x-y)^2'],\n",
" [8.90990894092236, 2.737081144057343, 6.172827796865017, 38.10380300974943],\n",
" [8.379390222857813, 2.899655491769051, 5.479734731088762, 30.027492723100423],\n",
" [1.9603923776987064,\n",
" 1.589157111785059,\n",
" 0.3712352659136475,\n",
" 0.1378156226579766],\n",
" [5.2988323329226645,\n",
" 2.6005868407377264,\n",
" 2.698245492184938,\n",
" 7.280528736096339],\n",
" [6.251549871509204,\n",
" 8.923856336119535,\n",
" -2.6723064646103305,\n",
" 7.141221840798163],\n",
" [3.8744158040817234,\n",
" 3.620802559246262,\n",
" 0.2536132448354613,\n",
" 0.06431967795597165],\n",
" [1.6908460868696873,\n",
" 5.998369056415042,\n",
" -4.307522969545355,\n",
" 18.55475413316083]]"
]
}
],
"prompt_number": 2
}
],
"metadata": {}
}
]
}