\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",
""
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['h', 'e', 'l', 'l', 'o']\n"
]
}
],
"source": [
"my_list = []\n",
"for letter in 'hello':\n",
" my_list.append(letter)\n",
"\n",
"print(my_list)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\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"
]
}
],
"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
}