{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 5.16 Two-Dimensional Lists" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating a Two-Dimensional List" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = [[77, 68, 86, 73], [96, 87, 89, 81], [70, 90, 86, 81]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Illustrating a Two-Dimensional List" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Identifying the Elements in a Two-Dimensional List" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for row in a:\n", " for item in row:\n", " print(item, end=' ')\n", " print()\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### How the Nested Loops Execute" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i, row in enumerate(a):\n", " for j, item in enumerate(row):\n", " print(f'a[{i}][{j}]={item} ', end=' ')\n", " print()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "##########################################################################\n", "# (C) Copyright 2019 by Deitel & Associates, Inc. and #\n", "# Pearson Education, Inc. All Rights Reserved. #\n", "# #\n", "# DISCLAIMER: The authors and publisher of this book have used their #\n", "# best efforts in preparing the book. These efforts include the #\n", "# development, research, and testing of the theories and programs #\n", "# to determine their effectiveness. The authors and publisher make #\n", "# no warranty of any kind, expressed or implied, with regard to these #\n", "# programs or to the documentation contained in these books. The authors #\n", "# and publisher shall not be liable in any event for incidental or #\n", "# consequential damages in connection with, or arising out of, the #\n", "# furnishing, performance, or use of these programs. #\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.7.7" } }, "nbformat": 4, "nbformat_minor": 4 }