{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A sample notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "print('hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "plt.plot(np.random.random(100))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A function for displaying the summary of a notebook object.\n",
    "It prints a simple summary, such as:\n",
    "\n",
    "```\n",
    "  1   markdown cells, total:   4 lines\n",
    "  5       code cells, total:   4 lines\n",
    "  1    heading cells, total:   1 lines\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def nb_info(nb):\n",
    "    \"\"\"display a summary of the contents of a notebook\"\"\"\n",
    "    cell_counts = {}\n",
    "    cell_lines = {}\n",
    "    \n",
    "    for cell in nb.cells:\n",
    "        cell_type = cell.cell_type\n",
    "        count = cell_counts.setdefault(cell_type, 0)\n",
    "        lines = cell_counts.setdefault(cell_type, 0)\n",
    "        cell_counts[cell_type] = count + 1\n",
    "        try:\n",
    "            content = cell.source\n",
    "        except AttributeError:\n",
    "            content = cell.input\n",
    "        cell_lines[cell_type] = lines + len(content.splitlines())\n",
    "    \n",
    "    for cell_type in cell_counts:\n",
    "        print(\"%3i %10s cells, total: %3i lines\" % (cell_counts[cell_type], cell_type, cell_lines[cell_type]))\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
