{ "metadata": { "name": "", "signature": "sha256:3d882ea980ba1e7af8041d815e717dd6868238d84f2284e6b6adc1b4617ed43c" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Nesting Lists\n", "\n", "- **Author:** [Chris Albon](http://www.chrisalbon.com/), [@ChrisAlbon](https://twitter.com/chrisalbon)\n", "- **Date:** -\n", "- **Repo:** [Python 3 code snippets for data science](https://github.com/chrisalbon/code_py)\n", "- **Note:**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Create a list of three nested lists, each with three items" ] }, { "cell_type": "code", "collapsed": false, "input": [ "state_regions = [['California', 'Oregon', 'Washington'],\n", " ['Texas','Georgia','Alabama'],\n", " ['Maine','Vermont','New York']]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# View the list" ] }, { "cell_type": "code", "collapsed": false, "input": [ "state_regions" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 9, "text": [ "[['California', 'Oregon', 'Washington'],\n", " ['Texas', 'Georgia', 'Alabama'],\n", " ['Maine', 'Vermont', 'New York']]" ] } ], "prompt_number": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Print the second list's third item" ] }, { "cell_type": "code", "collapsed": false, "input": [ "state_regions[1][2]" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 10, "text": [ "'Alabama'" ] } ], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }