{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6348e2ef",
   "metadata": {},
   "source": [
    "# In-Class Exercises, Session 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5cf2f368",
   "metadata": {},
   "source": [
    "COMMAND LINE"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "058e1aa8",
   "metadata": {},
   "source": [
    "<B>1.1:  Open a Command Prompt (Windows) or a Terminal window (Mac).  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8bb4108",
   "metadata": {},
   "source": [
    "<UL>\n",
    "  <LI> (Unix only) Use <B>pwd</B> to see the \"present working directory\"</LI>\n",
    "  <LI> Use <B>ls</B> (Mac) or <B>dir</B> (Windows) to see a listing of the files and directories in this directory</LI>\n",
    "  <LI> Use <B>cd</B> to move into a directory you see listed in the present working directory (for example <B>cd Downloads</B>)</LI>\n",
    "  <LI> Use <B>cd ..</B> to move into the \"parent\" directory of the one you are in (this will take you back to the parent of <B>Downlaods</B></LI>\n",
    "  <LI> Use <B>cd /Users/[yourhomedir]/Desktop</B> to move into the <B>Desktop</B> directory</LI>\n",
    "  <LI> Use <B>cd ../Downloads</B> to move from the <B>Desktop</B> directory to the <B>Downloads</B> directory</LI>\n",
    "  <LI> Use <B>cd</B> (Mac) or <B>cd %HOMEPATH%</B> (Windows) to move back into the home directory</LI>\n",
    "</UL>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0790b86e",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "affe07a8",
   "metadata": {},
   "source": [
    "ARGPARSE MODULE"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c475ea51",
   "metadata": {},
   "source": [
    "<B>1.2:  <U>Use <B>argparse</B> to accept a required argument from the command line</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "973231ff",
   "metadata": {},
   "source": [
    "Starting with the below code, use <B>parser.add\\_argument()</B> to add argument 'name'.  The argument should expect either <B>-n</B> or <B>--name</B> as identifier at the command line.  Include a <B>required=True</B> argument to make the argument required.\n",
    "\n",
    "Call <B>.parse\\_args()</B> on the <B>parser</B> object.  The program should then print the value of the 'name' argument.\n",
    "\n",
    "Test the program by running it from a Terminal or Command Prompt.\n",
    "\n",
    "Then, test it a second time by omitting the argument, and note that the <B>required=True</B> causes the program to output an error message.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bbd03674",
   "metadata": {},
   "outputs": [],
   "source": [
    "import argparse\n",
    "import os\n",
    "import sys\n",
    "\n",
    "parser = argparse.ArgumentParser(\n",
    "                    prog=os.path.basename(sys.argv[0]))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a5f16be",
   "metadata": {},
   "source": [
    "Sample Run (note that the '%' represents your command prompt - yours will look different)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "572955da",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">% python inclass_ex.py --name David\n",
    "David\n",
    "%  python inclass_ex.py\n",
    "usage: inclass_ex.py [-h] -n NAME\n",
    "inclass_ex.py: error: the following arguments are required: -n/--name</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae285c5b",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bff1b5d1",
   "metadata": {},
   "source": [
    "<B>1.3:  <U>View the help message</U>.  Starting with the above solution, add a <B>description=</B> argument to <B>ArgumentParser</B>; the value should be a string explaining what the program does.</B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c845e58",
   "metadata": {},
   "source": [
    "Call the same program with the <B>--help</B> or <B>-h</B> flag.  Note the automated output explaining how the program works.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26c92525",
   "metadata": {},
   "outputs": [],
   "source": [
    "import argparse\n",
    "import os\n",
    "import sys\n",
    "\n",
    "parser = argparse.ArgumentParser(\n",
    "                    prog=os.path.basename(sys.argv[0]))\n",
    "\n",
    "\n",
    "parser.add_argument('-n', '--name', required=True)\n",
    "\n",
    "args = parser.parse_args()\n",
    "\n",
    "print(args.name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e03ab8ad",
   "metadata": {},
   "source": [
    "<U>Sample program run</U>:  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "002ad6e1",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">% python inclass_ex.py --help\n",
    "usage: inclass_ex.py [-h] -n NAME\n",
    "\n",
    "prints your name!\n",
    "\n",
    "options:\n",
    "  -h, --help            show this help message and exit\n",
    "  -n NAME, --name NAME</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c923e8b",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53193d63",
   "metadata": {},
   "source": [
    "<B>1.4:  <U>Add an argument restricted to specific choices</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c740dcf5",
   "metadata": {},
   "source": [
    "Continue the same program; add an argument 'color' with the <B>choices=</B> argument.  Restrict the choices to blue, green or red.\n",
    "\n",
    "Print the value of the color argument.\n",
    "\n",
    "Call the program with a <B>--color</B> argument and one of the valid colors; then call the program with <B>--color</B> and an invalid choice; note that it is rejected.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "faf9968d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import argparse\n",
    "import os\n",
    "import sys\n",
    "\n",
    "parser = argparse.ArgumentParser(\n",
    "                    prog=os.path.basename(sys.argv[0]),\n",
    "                    description='prints your name!')\n",
    "\n",
    "\n",
    "parser.add_argument('-n', '--name', required=True)\n",
    "\n",
    "args = parser.parse_args()\n",
    "\n",
    "print(args.name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16af5b39",
   "metadata": {},
   "source": [
    "<U>Sample program run</U>:  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df7107f3",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">% python inclass_ex.py --name David --color red\n",
    "David\n",
    "red\n",
    "% python inclass_ex.py --name David --color purple\n",
    "usage: inclass_ex.py [-h] -n NAME [-c {red,blue,green}]\n",
    "inclass_ex.py: error: argument -c/--color: invalid choice: 'purple' (choose from 'red', 'blue', 'green')\n",
    "%</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33769898",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fce6c309",
   "metadata": {},
   "source": [
    "<B>1.5:  <U>Add an argument allowing multiple values</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fae20cb",
   "metadata": {},
   "source": [
    "Continue the same program; add argument <B>--cities</B> and add the <B>nargs='+'</B> argument to allow multiple values.\n",
    "\n",
    "Call the program with the <B>--cities</B> argument and a couple of city values.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3daddde9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import argparse\n",
    "import os\n",
    "import sys\n",
    "\n",
    "parser = argparse.ArgumentParser(\n",
    "                    prog=os.path.basename(sys.argv[0]),\n",
    "                    description='prints your name!')\n",
    "\n",
    "\n",
    "parser.add_argument('-n', '--name', required=True)\n",
    "parser.add_argument('-c', '--color', choices=['red', 'blue', 'green'])\n",
    "\n",
    "args = parser.parse_args()\n",
    "\n",
    "print(args.name)\n",
    "print(args.color)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84da526e",
   "metadata": {},
   "source": [
    "<U>Sample program run</U>:  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efd395e5",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">% python inclass_ex.py --name David --color red --cities Chicago 'New York'\n",
    "David\n",
    "red\n",
    "['Chicago', 'New York']\n",
    "%</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfc6ffdc",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e89d58b",
   "metadata": {},
   "source": [
    "CSV MODULE"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0aa9ce22",
   "metadata": {},
   "source": [
    "<B>1.6:  <U>Use <B>csv.reader</B> to read a file</U>.  Take the following steps, testing as you go:</B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bbb31985",
   "metadata": {},
   "source": [
    "<OL>\n",
    "  <LI>Open a file and pass the file object to <B>csv.reader()</B></LI>\n",
    "  <LI>Loop through the <B>reader</B> object line by line, printing each line.  Note the type of the object representing each row.</LI>\n",
    "  <LI>Subscript the float value from each list and convert to float.</LI>\n",
    "  <LI>Initialize a float variable <B>0.0</B> at the top and add each float value to it inside the loop, producing a sum.\n",
    "</OL>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1f51412",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "fh = open('../revenue.csv')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef746a06",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c0f39f3",
   "metadata": {},
   "source": [
    "<B>1.7:  <U>Use <B>csv.reader</B> to read the header of a file</U>.  Using the code solution from the previous exercise, before the <B>for</B> block, use a call to <B>next(reader)</B> to retrieve and print the header of the file, noting that the loop then begins on the next line of the file.  </B>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1de4829",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "fh = open('../revenue.csv')        # 'file' object\n",
    "\n",
    "reader = csv.reader(fh)            # csv.reader object\n",
    "\n",
    "fsum = 0.0                         # float, 0.0\n",
    "\n",
    "for row in reader:                 # list, [\"Haddad's\", 'PA', '239.5']\n",
    "    fval = floatrow[-1])           # float, 239.5\n",
    "    fsum = fsum + fval             # float, 239.5\n",
    "\n",
    "print(fsum)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4426d4e5",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a448856",
   "metadata": {},
   "source": [
    "<B>1.8:  <U>Write individual rows to a CSV file using <B>csv.writer</B></U>.  Take the following steps, testing as you go:</B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f153b246",
   "metadata": {},
   "source": [
    "<OL>\n",
    "  <LI>Open a file for writing and pass the filehandle to <B>csv.writer()</B> (when opening the file for writing, include the <B>newline=''</B> argument to <B>open()</B> so newlines will be written properly).</LI>\n",
    "  <LI>Use <B>.writerow()</B> on the writer object to write each list to the file, starting with the <B>header</B> list.</LI>\n",
    "  <LI>Close the file, then open and view <B>newfile.csv</B> in the session directory.</LI>\n",
    "</OL>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ed3db18",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "header = ['name', 'address', 'state', 'zip']\n",
    "\n",
    "row1 = ['Joe', '123 Main', 'CA', '91603']\n",
    "row2 = ['Marie', '234 Camarino', 'NJ', '92325']\n",
    "\n",
    "fname = '../newfile.csv'     # a new file, or replacing old if exists\n",
    "\n",
    "wfh = open(fname, 'w', newline='')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd5a236f",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "119d7e0f",
   "metadata": {},
   "source": [
    "<B>1.9:  <U>Write multiple rows to a CSV file using <B>csv.writer</B></U>.  Follow the same steps as above, but use <B>.writerows()</B> to write the entire list of lists to the file.  Close the file, then look for <B>newfile2.csv</B> in the session directory.  </B>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc383ac7",
   "metadata": {},
   "outputs": [],
   "source": [
    "rows = [\n",
    "         [ 'date', 'temp', 'wind' ],\n",
    "         [ '2020-06-13', '78.3', '6' ],\n",
    "         [ '2020-06-14', '77.0', '8' ],\n",
    "       ]\n",
    "\n",
    "fname = '../newfile2.csv'\n",
    "\n",
    "wfh = open(fname, 'w', newline='')\n",
    "\n",
    "writer = csv.writer(wfh)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "520ed1a2",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de4205a1",
   "metadata": {},
   "source": [
    "<B>1.10:  <U>Use <B>csv.writer</B> to selectively write rows to a CSV</U>.  Loop through the list of lists and write only the <B>US</B> rows to the file.  Also write the header as the first row.  Close the file, then look for <B>newfile3.csv</B> in the session directory.  </B>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b94471b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "rows = [\n",
    "         [ 'company', 'state/province', 'country' ],\n",
    "         [ 'Acme', 'Caliornia', 'US' ],\n",
    "         [ 'Bento', 'Toledo', 'SP' ],\n",
    "         [ 'OuiOui', 'Bourges', 'FR' ],\n",
    "         [ 'Beta', 'New York', 'US' ]\n",
    "       ]\n",
    "\n",
    "fname = '../newfile3.csv'\n",
    "\n",
    "wfh = open(fname, 'w', newline='')\n",
    "writer = csv.writer(wfh)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84aa42f7",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e0cf752",
   "metadata": {},
   "source": [
    "<B>1.11:  <U>Use <B>csv.writer</B> to selectively write columns to a CSV</U>.  Loop through the list of lists and write only the <B>company</B> and <B>country</B> columns to the file.  Include the header.  Close the file, then look for <B>newfile4.csv</B> in the session directory.  </B>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "023e0316",
   "metadata": {},
   "outputs": [],
   "source": [
    "rows = [\n",
    "         [ 'company', 'state/province', 'country' ],\n",
    "         [ 'Acme', 'Caliornia', 'US' ],\n",
    "         [ 'Bento', 'Toledo', 'SP' ],\n",
    "         [ 'OuiOui', 'Bourges', 'FR' ],\n",
    "         [ 'Beta', 'New York', 'US' ]\n",
    "       ]\n",
    "\n",
    "fname = '../newfile4.csv'\n",
    "\n",
    "wfh = open(fname, 'w', newline='')\n",
    "writer = csv.writer(wfh)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d3f7072",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c79f006",
   "metadata": {},
   "source": [
    "<B>1.12:  <U>Use <B>csv.DictReader</B> to read a file line-by-line, each line a dict</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "688c105a",
   "metadata": {},
   "source": [
    "As you loop through the <B>DictReader</B> object, print each row dict.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fef9986d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "fname = '../revenue.csv'\n",
    "\n",
    "fh = open(fname)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a70dd2f",
   "metadata": {},
   "source": [
    "<U>Expected Output</U>:  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be035dfd",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">{'company': \"Haddad's, Inc.\", 'state': 'PA', 'price': '239.5'}\n",
    "{'company': 'Westfield', 'state': 'NJ', 'price': '53.9'}\n",
    "{'company': 'The Store', 'state': 'NJ', 'price': '211.5'}\n",
    "{'company': \"Hipster's\", 'state': 'NY', 'price': '11.98'}\n",
    "{'company': 'Dothraki Fashions', 'state': 'NY', 'price': '5.98'}\n",
    "{'company': \"Awful's\", 'state': 'PA', 'price': '23.95'}\n",
    "{'company': 'The Clothiers', 'state': 'NY', 'price': '115.2'}</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c231e0be",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1ff1b2d",
   "metadata": {},
   "source": [
    "<B>1.13:  <U>Use <B>csv.DictReader</B> to read the header line of a file</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ffe4367",
   "metadata": {},
   "source": [
    "Continue the previous solution -- read and print the file's headers using the <B>.fieldnames</B> attribute.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06d253c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "fname = '../revenue.csv'\n",
    "\n",
    "fh = open(fname)\n",
    "\n",
    "dreader = csv.DictReader(fh)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8153db09",
   "metadata": {},
   "source": [
    "<U>Expected Output</U>:  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f391e03a",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">['company', 'state', 'price']</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9cc31b3b",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23f5f2ea",
   "metadata": {},
   "source": [
    "<B>1.14:  <U>Use <B>csv.DictWriter</B> to write a header to a file</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0e994be",
   "metadata": {},
   "source": [
    "Starting with the following filename and headers list, open the file for writing, then instantiate a <B>csv.DictWriter</B> object with the file object and headers; use the <B>.writeheader()</B> argument to write the header row.\n",
    "\n",
    "Make sure to close the write filehandle with <B>.close()</B> (make sure to include the parentheses!) after all writing is done.\n",
    "\n",
    "Run the program, then check the file to see that it has been created and contains the headers\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d296e67b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "filename = '../newfile.csv'\n",
    "\n",
    "headers = ['fname', 'lname', 'state']\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6a1581f",
   "metadata": {},
   "source": [
    "After running, the file <B>newfile.csv</B> in the parent directory should have the following text:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1895d91",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">fname,lname,state</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "532044d1",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbf02d67",
   "metadata": {},
   "source": [
    "<B>1.15:  <U>Use <B>csv.DictWriter</B> to write lines to a file</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a29df37c",
   "metadata": {},
   "source": [
    "Continuing from the previous solution (below, with some data line dictionaries added), use <B>.writerow()</B> to write the dicts to the file.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "377e8249",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "filename = 'newfile.csv'\n",
    "\n",
    "headers = ['fname', 'lname', 'state']\n",
    "\n",
    "data_lines = [\n",
    "               { 'fname': 'Joe', 'lname': 'Wilson', 'state': 'CA' },\n",
    "               { 'fname': 'Mike', 'lname': 'Sanchez', 'state': 'NY' },\n",
    "               { 'fname': 'Marie', 'lname': 'Obubwe', 'state': 'NJ' },\n",
    "             ]\n",
    "\n",
    "wfh = open(filename, 'w')\n",
    "\n",
    "dwriter = csv.DictWriter(wfh, headers)\n",
    "\n",
    "dwriter.writeheader()\n",
    "\n",
    "wfh.close()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ca89f576",
   "metadata": {},
   "source": [
    "After running, the file <B>newfile.csv</B> in the parent directory should have the following text:"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d0ff89f",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">fname,lname,state\n",
    "Joe,Wilson,CA\n",
    "Mike,Sanchez,NY\n",
    "Marie,Obubwe,NJ</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f782dc66",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c83002b9",
   "metadata": {},
   "source": [
    "<B>1.16:  <U>Create a dictionary by zipping up two lists</U>.  </B>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "735439b1",
   "metadata": {},
   "source": [
    "Given the following list of headers and data row, use <B>dict(zip())</B> with the two lists to zip the two lists together into a list of 2-item tuples, and convert them to a dict.  Print the dict.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d075e62",
   "metadata": {},
   "outputs": [],
   "source": [
    "headers = ['fname', 'lname', 'state']\n",
    "\n",
    "data = ['Joe', 'Wilson', 'CA']\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71564cb0",
   "metadata": {},
   "source": [
    "<U>Expected Output</U>:  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5683a39",
   "metadata": {},
   "source": [
    "<pre style=\"margin: 0; padding=0\"><DIV style=\"font-family: Courier; border: 1px solid #dbdbdb; padding: 7px\">{'fname': 'Joe', 'lname': 'Wilson', 'state': 'CA'}</DIV></pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21e13b7b",
   "metadata": {},
   "source": [
    " "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
