{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%reload_ext nbtutor" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%nbtutor -r -f -d 5\n", "class Foo(object):\n", " a = 10\n", " def __init__(self, b):\n", " self.b = b\n", " \n", " def dostuff(self, x):\n", " self.b += x\n", " return self.b\n", "\n", "foo = Foo(10)\n", "ans = foo.dostuff(100)\n", "print(ans)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%nbtutor -r -f\n", "import math\n", "\n", "def fubar(eggs, spam):\n", " foo = eggs * spam\n", " return foo\n", "\n", "bar = fubar(0.1, 103)\n", "print(bar)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%nbtutor -r -f -d 5\n", "def fib(n):\n", " a, b = 1, 1\n", " for i in range(n):\n", " yield a\n", " a, b = b, a+b\n", "\n", "ans = list(fib(5))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%nbtutor -r -f -d 15\n", "def fib(n):\n", " if n <= 2:\n", " return [1] * n\n", " prev = fib(n-1)\n", " return prev + [prev[-2] + prev[-1]]\n", "\n", "ans = fib(5)\n", "print(ans)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%nbtutor -r -f -d 15\n", "a = {'foo': 100}\n", "keys, values = zip(*a.items())\n", "print(list(keys), list(values))\n", "\n", "for i in a:\n", " print(i)\n", "\n", "items = sorted(a.items(), key=lambda x: x[0])\n", "keys, values = zip(*items)\n", "print(list(keys), list(values))" ] } ], "metadata": { "anaconda-cloud": {}, "celltoolbar": "Visualize", "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.8.2" } }, "nbformat": 4, "nbformat_minor": 1 }