{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Parallel lists" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's write a function that compares two lists to see if they are the same" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def lists_equal(L1, L2):\n", " '''Return True iff L1 and L2 have the same contents\n", " \n", " Arguments:\n", " L1, L2 -- lists of integers\n", " '''\n", " # Need to check whether the two lists are the same length first, \n", " # since otherwise we'll get an out-of-range error in the for-loop\n", " if len(L1) != len(L2):\n", " return False\n", " \n", " for i in range(len(L1)):\n", " if L1[i] != L2[i]:\n", " return False\n", " \n", " return True\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Switch to Problem 6.1\n", "### Switch to Problem 6.2\n", "### Switch to Problem 6.3\n", "### Switch to Problem 6.4" ] } ], "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.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }