{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Storing Multiple Values in Lists\n", "\n", "
\n", "
\n", "
\n", "

## Learning Objectives

\n", "
\n", "
\n", "
• Explain what a list is
• \n", "
• Create and index lists of simple values
• \n", "
\n", "
\n", "
\n", "

## Turn a string into a list

\n", "
\n", "
\n", "Use a for-loop to convert the string `“hello”` into a list of letters.\n", "
`[\"h\", \"e\", \"l\", \"l\", \"o\"]`
\n", "\n", "NB: you can create an empty list using `my_list = []`\n", " \n", "
\n", "\n", "
\n", "
\n", "

## Tuples and Excahnges

\n", "
\n", "
\n", "Use a for-loop to convert the string `“hello”` into a list of letters.\n", "
`[\"h\", \"e\", \"l\", \"l\", \"o\"]`
\n", "\n", "Explain what the overall effect of this code is:\n", "\n", "
```\n",
"left = 'L'\n",
"right = 'R'\n",
"\n",
"temp = left\n",
"left = right\n",
"right = temp\n",
"```
\n", "
\n", "Compare it to:\n", "
` left, right = right, left `
\n", "
\n", "Do they always do the same thing? Which does your brain scan better?\n", "
\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python2", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }