{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "plt.rc('figure', figsize=(10, 6))\n", "PREVIOUS_MAX_ROWS = pd.options.display.max_rows\n", "pd.options.display.max_columns = 20\n", "pd.options.display.max_rows = 20\n", "pd.options.display.max_colwidth = 80\n", "np.set_printoptions(precision=4, suppress=True)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# a very large list of strings\n", "strings = ['foo', 'foobar', 'baz', 'qux',\n", " 'python', 'Guido Van Rossum'] * 100000\n", "\n", "method1 = [x for x in strings if x.startswith('foo')]\n", "\n", "method2 = [x for x in strings if x[:3] == 'foo']" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "%time method1 = [x for x in strings if x.startswith('foo')]\n", "%time method2 = [x for x in strings if x[:3] == 'foo']" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "pd.options.display.max_rows = PREVIOUS_MAX_ROWS" ] } ], "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }