{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6b4fce18-128e-441d-9040-7d738b1ac1c8",
   "metadata": {},
   "source": [
    "## PDSP 2025, Lecture 02, 12 August 2025"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "879ec57a-2e55-4547-9e93-fbea876fdcbf",
   "metadata": {},
   "source": [
    "## Set up the table as a list\n",
    "- Assign a value to a variable: `variable = value`\n",
    "- Each entry is a row\n",
    "- Each row is a tuple of columns \n",
    "- `(Venue, Team 1, Team 2, Toss winner, Match winner, Run target)`\n",
    "- `Run target` is an integer, all other columns are text (`String`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "90dd963d-bf0a-4fa5-963d-1f79a418243d",
   "metadata": {},
   "outputs": [],
   "source": [
    "matchlist = [\n",
    "    (\"Chennai\",\"RCB\",\"CSK\",\"RCB\",\"CSK\",174),\n",
    "    (\"Mohali\",\"DC\",\"PK\",\"PK\",\"PK\",175),\n",
    "    (\"Kolkata\",\"KKR\",\"SRH\",\"SRH\",\"KKR\",209),\n",
    "    (\"Jaipur\",\"RR\",\"LSG\",\"RR\",\"RR\",194),\n",
    "    (\"Ahmedabad\",\"GT\",\"MI\",\"MI\",\"GT\",169),\n",
    "    (\"Bengaluru\",\"PK\",\"RCB\",\"RCB\",\"RCB\",177),\n",
    "    (\"Chennai\",\"CSK\",\"GT\",\"GT\",\"CSK\",207),\n",
    "    (\"Hyderabad\",\"SRH\",\"MI\",\"MI\",\"SRH\",278),\n",
    "    (\"Jaipur\",\"RR\",\"DC\",\"DC\",\"RR\",186),\n",
    "    (\"Bengaluru\",\"RCB\",\"KKR\",\"KKR\",\"KKR\",183),\n",
    "    (\"Lucknow\",\"LSG\",\"PK\",\"LSG\",\"LSG\",200),\n",
    "    (\"Ahmedabad\",\"SRH\",\"GT\",\"SRH\",\"GT\",163),\n",
    "    (\"Visakhapatnam\",\"DC\",\"CSK\",\"DC\",\"DC\",192),\n",
    "    (\"Mumbai\",\"MI\",\"RR\",\"RR\",\"RR\",126),\n",
    "    (\"Bengaluru\",\"LSG\",\"RCB\",\"RCB\",\"LSG\",182),\n",
    "    (\"Visakhapatnam\",\"KKR\",\"DC\",\"KKR\",\"KKR\",273),\n",
    "    (\"Ahmedabad\",\"GT\",\"PK\",\"PK\",\"PK\",200),\n",
    "    (\"Hyderabad\",\"CSK\",\"SRH\",\"SRH\",\"SRH\",166),\n",
    "    (\"Jaipur\",\"RCB\",\"RR\",\"RR\",\"RR\",184),\n",
    "    (\"Mumbai\",\"MI\",\"DC\",\"DC\",\"MI\",235),\n",
    "    (\"Lucknow\",\"LSG\",\"GT\",\"LSG\",\"LSG\",164),\n",
    "    (\"Chennai\",\"KKR\",\"CSK\",\"CSK\",\"CSK\",138),\n",
    "    (\"Mohali\",\"SRH\",\"PK\",\"PK\",\"SRH\",183),\n",
    "    (\"Jaipur\",\"RR\",\"GT\",\"GT\",\"GT\",197),\n",
    "    (\"Mumbai\",\"RCB\",\"MI\",\"MI\",\"MI\",197),\n",
    "    (\"Lucknow\",\"LSG\",\"DC\",\"LSG\",\"DC\",168),\n",
    "    (\"Mohali\",\"PK\",\"RR\",\"RR\",\"RR\",148),\n",
    "    (\"Kolkata\",\"LSG\",\"KKR\",\"KKR\",\"KKR\",162),\n",
    "    (\"Mumbai\",\"CSK\",\"MI\",\"MI\",\"CSK\",207),\n",
    "    (\"Bengaluru\",\"SRH\",\"RCB\",\"RCB\",\"SRH\",288),\n",
    "    (\"Kolkata\",\"KKR\",\"RR\",\"RR\",\"RR\",224),\n",
    "    (\"Ahmedabad\",\"GT\",\"DC\",\"DC\",\"DC\",90),\n",
    "    (\"Mohali\",\"MI\",\"PK\",\"PK\",\"MI\",193),\n",
    "    (\"Lucknow\",\"CSK\",\"LSG\",\"LSG\",\"LSG\",177),\n",
    "    (\"Delhi\",\"SRH\",\"DC\",\"DC\",\"SRH\",267),\n",
    "    (\"Kolkata\",\"KKR\",\"RCB\",\"RCB\",\"KKR\",223),\n",
    "    (\"Mohali\",\"PK\",\"GT\",\"PK\",\"GT\",143),\n",
    "    (\"Jaipur\",\"MI\",\"RR\",\"MI\",\"RR\",180),\n",
    "    (\"Chennai\",\"CSK\",\"LSG\",\"LSG\",\"LSG\",211),\n",
    "    (\"Delhi\",\"DC\",\"GT\",\"GT\",\"DC\",225),\n",
    "    (\"Hyderabad\",\"RCB\",\"SRH\",\"RCB\",\"RCB\",207),\n",
    "    (\"Kolkata\",\"KKR\",\"PK\",\"PK\",\"PK\",262),\n",
    "    (\"Delhi\",\"DC\",\"MI\",\"MI\",\"DC\",258),\n",
    "    (\"Lucknow\",\"LSG\",\"RR\",\"RR\",\"RR\",197),\n",
    "    (\"Ahmedabad\",\"GT\",\"RCB\",\"RCB\",\"RCB\",201),\n",
    "    (\"Chennai\",\"CSK\",\"SRH\",\"SRH\",\"CSK\",213),\n",
    "    (\"Kolkata\",\"DC\",\"KKR\",\"DC\",\"KKR\",154),\n",
    "    (\"Lucknow\",\"MI\",\"LSG\",\"LSG\",\"LSG\",145),\n",
    "    (\"Chennai\",\"CSK\",\"PK\",\"PK\",\"PK\",163),\n",
    "    (\"Hyderabad\",\"SRH\",\"RR\",\"SRH\",\"SRH\",202),\n",
    "    (\"Mumbai\",\"KKR\",\"MI\",\"MI\",\"KKR\",170),\n",
    "    (\"Bengaluru\",\"GT\",\"RCB\",\"RCB\",\"RCB\",148),\n",
    "    (\"Dharamsala\",\"CSK\",\"PK\",\"PK\",\"CSK\",168),\n",
    "    (\"Lucknow\",\"KKR\",\"LSG\",\"LSG\",\"KKR\",236),\n",
    "    (\"Mumbai\",\"SRH\",\"MI\",\"MI\",\"MI\",174),\n",
    "    (\"Delhi\",\"DC\",\"RR\",\"RR\",\"DC\",222),\n",
    "    (\"Hyderabad\",\"LSG\",\"SRH\",\"LSG\",\"SRH\",166),\n",
    "    (\"Dharamsala\",\"RCB\",\"PK\",\"PK\",\"RCB\",242),\n",
    "    (\"Ahmedabad\",\"GT\",\"CSK\",\"CSK\",\"GT\",232),\n",
    "    (\"Kolkata\",\"KKR\",\"MI\",\"MI\",\"KKR\",158),\n",
    "    (\"Chennai\",\"RR\",\"CSK\",\"RR\",\"CSK\",142),\n",
    "    (\"Bengaluru\",\"RCB\",\"DC\",\"DC\",\"RCB\",188),\n",
    "    (\"Delhi\",\"DC\",\"LSG\",\"LSG\",\"DC\",209),\n",
    "    (\"Guwahati\",\"RR\",\"PK\",\"RR\",\"PK\",145),\n",
    "    (\"Mumbai\",\"LSG\",\"MI\",\"MI\",\"LSG\",215),\n",
    "    (\"Bengaluru\",\"RCB\",\"CSK\",\"CSK\",\"RCB\",219),\n",
    "    (\"Hyderabad\",\"PK\",\"SRH\",\"PK\",\"SRH\",215),\n",
    "    (\"Ahmedabad\",\"SRH\",\"KKR\",\"SRH\",\"KKR\",160),\n",
    "    (\"Ahmedabad\",\"RCB\",\"RR\",\"RR\",\"RR\",173),\n",
    "    (\"Chennai\",\"SRH\",\"RR\",\"RR\",\"SRH\",176),\n",
    "    (\"Chennai\",\"SRH\",\"KKR\",\"SRH\",\"KKR\",114)\n",
    "]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5bd40f0-ca24-43db-9a69-2d55d22e1960",
   "metadata": {},
   "source": [
    "- Can evaluate the value of a variable directly in a Jupyter notebook cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d5b3432e-69c2-4d36-9ef8-5fd5b266ed8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Chennai', 'RCB', 'CSK', 'RCB', 'CSK', 174),\n",
       " ('Mohali', 'DC', 'PK', 'PK', 'PK', 175),\n",
       " ('Kolkata', 'KKR', 'SRH', 'SRH', 'KKR', 209),\n",
       " ('Jaipur', 'RR', 'LSG', 'RR', 'RR', 194),\n",
       " ('Ahmedabad', 'GT', 'MI', 'MI', 'GT', 169),\n",
       " ('Bengaluru', 'PK', 'RCB', 'RCB', 'RCB', 177),\n",
       " ('Chennai', 'CSK', 'GT', 'GT', 'CSK', 207),\n",
       " ('Hyderabad', 'SRH', 'MI', 'MI', 'SRH', 278),\n",
       " ('Jaipur', 'RR', 'DC', 'DC', 'RR', 186),\n",
       " ('Bengaluru', 'RCB', 'KKR', 'KKR', 'KKR', 183),\n",
       " ('Lucknow', 'LSG', 'PK', 'LSG', 'LSG', 200),\n",
       " ('Ahmedabad', 'SRH', 'GT', 'SRH', 'GT', 163),\n",
       " ('Visakhapatnam', 'DC', 'CSK', 'DC', 'DC', 192),\n",
       " ('Mumbai', 'MI', 'RR', 'RR', 'RR', 126),\n",
       " ('Bengaluru', 'LSG', 'RCB', 'RCB', 'LSG', 182),\n",
       " ('Visakhapatnam', 'KKR', 'DC', 'KKR', 'KKR', 273),\n",
       " ('Ahmedabad', 'GT', 'PK', 'PK', 'PK', 200),\n",
       " ('Hyderabad', 'CSK', 'SRH', 'SRH', 'SRH', 166),\n",
       " ('Jaipur', 'RCB', 'RR', 'RR', 'RR', 184),\n",
       " ('Mumbai', 'MI', 'DC', 'DC', 'MI', 235),\n",
       " ('Lucknow', 'LSG', 'GT', 'LSG', 'LSG', 164),\n",
       " ('Chennai', 'KKR', 'CSK', 'CSK', 'CSK', 138),\n",
       " ('Mohali', 'SRH', 'PK', 'PK', 'SRH', 183),\n",
       " ('Jaipur', 'RR', 'GT', 'GT', 'GT', 197),\n",
       " ('Mumbai', 'RCB', 'MI', 'MI', 'MI', 197),\n",
       " ('Lucknow', 'LSG', 'DC', 'LSG', 'DC', 168),\n",
       " ('Mohali', 'PK', 'RR', 'RR', 'RR', 148),\n",
       " ('Kolkata', 'LSG', 'KKR', 'KKR', 'KKR', 162),\n",
       " ('Mumbai', 'CSK', 'MI', 'MI', 'CSK', 207),\n",
       " ('Bengaluru', 'SRH', 'RCB', 'RCB', 'SRH', 288),\n",
       " ('Kolkata', 'KKR', 'RR', 'RR', 'RR', 224),\n",
       " ('Ahmedabad', 'GT', 'DC', 'DC', 'DC', 90),\n",
       " ('Mohali', 'MI', 'PK', 'PK', 'MI', 193),\n",
       " ('Lucknow', 'CSK', 'LSG', 'LSG', 'LSG', 177),\n",
       " ('Delhi', 'SRH', 'DC', 'DC', 'SRH', 267),\n",
       " ('Kolkata', 'KKR', 'RCB', 'RCB', 'KKR', 223),\n",
       " ('Mohali', 'PK', 'GT', 'PK', 'GT', 143),\n",
       " ('Jaipur', 'MI', 'RR', 'MI', 'RR', 180),\n",
       " ('Chennai', 'CSK', 'LSG', 'LSG', 'LSG', 211),\n",
       " ('Delhi', 'DC', 'GT', 'GT', 'DC', 225),\n",
       " ('Hyderabad', 'RCB', 'SRH', 'RCB', 'RCB', 207),\n",
       " ('Kolkata', 'KKR', 'PK', 'PK', 'PK', 262),\n",
       " ('Delhi', 'DC', 'MI', 'MI', 'DC', 258),\n",
       " ('Lucknow', 'LSG', 'RR', 'RR', 'RR', 197),\n",
       " ('Ahmedabad', 'GT', 'RCB', 'RCB', 'RCB', 201),\n",
       " ('Chennai', 'CSK', 'SRH', 'SRH', 'CSK', 213),\n",
       " ('Kolkata', 'DC', 'KKR', 'DC', 'KKR', 154),\n",
       " ('Lucknow', 'MI', 'LSG', 'LSG', 'LSG', 145),\n",
       " ('Chennai', 'CSK', 'PK', 'PK', 'PK', 163),\n",
       " ('Hyderabad', 'SRH', 'RR', 'SRH', 'SRH', 202),\n",
       " ('Mumbai', 'KKR', 'MI', 'MI', 'KKR', 170),\n",
       " ('Bengaluru', 'GT', 'RCB', 'RCB', 'RCB', 148),\n",
       " ('Dharamsala', 'CSK', 'PK', 'PK', 'CSK', 168),\n",
       " ('Lucknow', 'KKR', 'LSG', 'LSG', 'KKR', 236),\n",
       " ('Mumbai', 'SRH', 'MI', 'MI', 'MI', 174),\n",
       " ('Delhi', 'DC', 'RR', 'RR', 'DC', 222),\n",
       " ('Hyderabad', 'LSG', 'SRH', 'LSG', 'SRH', 166),\n",
       " ('Dharamsala', 'RCB', 'PK', 'PK', 'RCB', 242),\n",
       " ('Ahmedabad', 'GT', 'CSK', 'CSK', 'GT', 232),\n",
       " ('Kolkata', 'KKR', 'MI', 'MI', 'KKR', 158),\n",
       " ('Chennai', 'RR', 'CSK', 'RR', 'CSK', 142),\n",
       " ('Bengaluru', 'RCB', 'DC', 'DC', 'RCB', 188),\n",
       " ('Delhi', 'DC', 'LSG', 'LSG', 'DC', 209),\n",
       " ('Guwahati', 'RR', 'PK', 'RR', 'PK', 145),\n",
       " ('Mumbai', 'LSG', 'MI', 'MI', 'LSG', 215),\n",
       " ('Bengaluru', 'RCB', 'CSK', 'CSK', 'RCB', 219),\n",
       " ('Hyderabad', 'PK', 'SRH', 'PK', 'SRH', 215),\n",
       " ('Ahmedabad', 'SRH', 'KKR', 'SRH', 'KKR', 160),\n",
       " ('Ahmedabad', 'RCB', 'RR', 'RR', 'RR', 173),\n",
       " ('Chennai', 'SRH', 'RR', 'RR', 'SRH', 176),\n",
       " ('Chennai', 'SRH', 'KKR', 'SRH', 'KKR', 114)]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "matchlist"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b57c6ac8-7256-4370-9889-b2497517c07c",
   "metadata": {},
   "source": [
    "- Any expression can be evaluated in a Jupyter notebook cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a1cc551f-e92e-4120-a388-c540457128ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "7+3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dd09d100-7f2a-44d7-bd88-3e8b3b46e301",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = 9\n",
    "y = x + 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "3ac61fef-730e-4cba-a09e-f6c891981c30",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6d6a362-f403-4f5e-b439-07b5e4423adc",
   "metadata": {},
   "source": [
    "## Questions\n",
    "- How many matches were played?\n",
    "- What was the maximum run target?\n",
    "- What was the average run target?\n",
    "- How many matches had above average run targets?\n",
    "- How many cities were venues?\n",
    "- Which team played as Team 1 at maximum number of venues?\n",
    "- Is winning the toss an advantage?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c53a1966-e39a-4528-85a4-6787b44b3931",
   "metadata": {},
   "source": [
    "## How many matches were played?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e952ea5-1e00-473f-a3fd-b43f1d6cb2e8",
   "metadata": {},
   "source": [
    "- Python's built-in function `len()` directly tells the length of a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b0274e7e-5b17-4c19-82c9-ec220c400cfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "71"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(matchlist)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "82ccdeb1-0118-4c1b-9368-0ac3afe3a382",
   "metadata": {},
   "source": [
    "## Count the number of entries explicitly\n",
    "- Iterate through the list\n",
    "- `for` variable `in` listname `:`\n",
    "    - `:` indicates a block of statements (commands) to follow\n",
    "    - Indent the commands to be performed within each iteration\n",
    "- `count = count + 1`\n",
    "    - `=` assigns a new value to a variable, not to be confused with equality\n",
    "    - rhs is old value of `count`, used to update the value of `count`\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "145e7238-c606-4cfe-a9a4-5b51618edc73",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "for row in matchlist:\n",
    "    count = count + 1  # Compute current count + 1 and reassign it to count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e20b08cd-450b-49eb-b59a-9bedf2641952",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "71"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "count"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "212f94c8-d9ea-4992-954b-0ec57606c63c",
   "metadata": {},
   "source": [
    "- Python does not require you to \"declare\" variables in advance\n",
    "- Can introduce new names on the fly\n",
    "- This can be a source of errors, if you mistype a name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "04d1c02e-3eef-4e00-8b9c-8d11e37f019d",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "for row in matchlist:\n",
    "    countt = count + 1  # Compute current count + 1 and reassign it to count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8f35176a-7dc5-4aa6-9bd3-db0452075171",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "count"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62fbe007-2303-4773-851e-04128d6677ca",
   "metadata": {},
   "source": [
    "- If you are lucky, the mistyped name will appear on the right and Python will flag an error"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "31dbd6a5-bf92-4e54-95b1-2ada22b48fcb",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'ccount' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mNameError\u001b[39m                                 Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m      1\u001b[39m count = \u001b[32m0\u001b[39m\n\u001b[32m      2\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m row \u001b[38;5;129;01min\u001b[39;00m matchlist:\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m     count = \u001b[43mccount\u001b[49m + \u001b[32m1\u001b[39m  \u001b[38;5;66;03m# Compute current count + 1 and reassign it to count\u001b[39;00m\n",
      "\u001b[31mNameError\u001b[39m: name 'ccount' is not defined"
     ]
    }
   ],
   "source": [
    "count = 0\n",
    "for row in matchlist:\n",
    "    count = ccount + 1  # Compute current count + 1 and reassign it to count"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc8bfeb3-cd45-4cef-a8ec-cbac953334d5",
   "metadata": {},
   "source": [
    "## What was the maximum run target?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c186fd50-b24c-4f01-abe3-8fbd783255dd",
   "metadata": {},
   "source": [
    "- Initialize `maxtarget` to `-1`\n",
    "- Update `maxtarget` whenever run target in current row exceeds current maximum\n",
    "    - Extract run target from tuple of values of current row using positional index\n",
    "    - In Python, indices always start with 0, so six entries in the tuple have indices 0,1,2,3,4,5\n",
    "- `if`specifies conditional execution\n",
    "    - `if` conditional-expression `:`\n",
    "        - Expression evaluates to `True` or `False`\n",
    "        - As before, `:` and indentation indicate scope of conditional execution\n",
    "        - Indented commands (update of `maxtarget`) happens only when `if` condition evaluates to `True`\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0da23d78-4dcc-4f1d-b7b2-9736f457e222",
   "metadata": {},
   "outputs": [],
   "source": [
    "maxtarget = -1\n",
    "for row in matchlist:\n",
    "    target = row[5] # Sixth component, indexed 0,1,..,5\n",
    "    if target > maxtarget:\n",
    "        maxtarget = target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e82adc2d-c22f-482b-8524-28bb16aac506",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "288"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maxtarget"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8e9f053-1308-4474-9aa7-825848ea96c1",
   "metadata": {},
   "source": [
    "- No need to assign a separate variable for `row[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a6fe11c3-de3f-4c8d-a83a-51c8590e0775",
   "metadata": {},
   "outputs": [],
   "source": [
    "maxtarget = -1\n",
    "for row in matchlist:\n",
    "    if row[5] > maxtarget:\n",
    "        maxtarget = row[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d98d5d27-4315-4762-8ca3-701b0fda33aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "288"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maxtarget"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a08a668-1926-4b6a-b34e-b8a57da337f0",
   "metadata": {},
   "source": [
    "- Can also initialize `maxtarget` to first target in the table\n",
    "- Not a problem to read the first row of the table again"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b1082273-f302-48ba-bcf5-76162cb74d4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "firstrow = matchlist[0]\n",
    "maxtarget = firstrow[5]\n",
    "for row in matchlist:  # Not a problem to read first row again\n",
    "    if row[5] > maxtarget:\n",
    "        maxtarget = row[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c59b749b-b9a5-4fc0-b75f-fecc6a36a81c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "288"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maxtarget"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ad9f07f-9d4c-438f-95e8-d31ab33e0312",
   "metadata": {},
   "source": [
    "## What was the average run target?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0e28915-9e9c-432a-8441-0c7ce319aa06",
   "metadata": {},
   "source": [
    "- Iterate to compute sum of all run targets\n",
    "- Average is total divided by count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9fc94d02-9cf8-4b38-9110-28262301035f",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "targetsum = 0\n",
    "for row in matchlist: \n",
    "    count = count+1\n",
    "    targetsum = targetsum + row[5]\n",
    "targetavg = targetsum/count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "a7e6a2f3-0e75-4946-b613-794ce1727ee6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "190.59154929577466"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "targetavg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbc0cb72-3a73-4c5d-877c-9b138f696606",
   "metadata": {},
   "source": [
    "- Can also maintain running average instead of running total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "78df06ef-c03a-4586-b2d1-77b29698ba6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "currentavg = 0\n",
    "for row in matchlist:\n",
    "    totalsofar = count*currentavg\n",
    "    count = count+1\n",
    "    currentavg = (totalsofar + row[5])/count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "68c3fa3f-6ea8-499e-ad0a-a03b6a317154",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "190.59154929577466"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "currentavg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4faac400-8cb7-4b96-980c-fc7b4fc32a6c",
   "metadata": {},
   "source": [
    "- Alternatively, avoid creating running total altogether\n",
    "- Note that `count` has already been incremented, so multiply `currentavg` by `count-1`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9764fca3-b1e6-48b5-8e46-d6405a3a3a45",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "currentavg = 0\n",
    "for row in matchlist:\n",
    "    count = count+1\n",
    "    currentavg = (currentavg*(count-1) + row[5])/count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "1b6381d3-868d-4047-8078-c7e1e951d76d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "190.59154929577466"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "currentavg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "616fcef6-d8be-4b43-a504-1940030856cf",
   "metadata": {},
   "source": [
    "## How many matches had above average run targets?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "412b1eeb-b29f-4c79-b0c4-319812ae2a3c",
   "metadata": {},
   "source": [
    "- *Filtered* iteration\n",
    "- Update the count only if the current run target is $\\gt$ average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "4e613662-7d48-4230-b1c9-ed498c4037f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "count = 0\n",
    "targetsum = 0\n",
    "for row in matchlist: \n",
    "    count = count+1\n",
    "    targetsum = targetsum + row[5]\n",
    "targetavg = targetsum/count\n",
    "\n",
    "aboveavgcount = 0\n",
    "for row in matchlist:\n",
    "    if row[5] > targetavg:\n",
    "        aboveavgcount = aboveavgcount + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f7023f58-8906-4379-8353-4e0e8c4a1bbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "34"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aboveavgcount"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecbb55de-4e53-4f9b-a685-84ba936c26dc",
   "metadata": {},
   "source": [
    "## How many cities were venues?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69f8a0aa-ff7d-4746-8c5c-95c51dbbb2f8",
   "metadata": {},
   "source": [
    "- Maintain a list of venues\n",
    "    - Need to initialize to empty list to tell Python this value can be used as a list\n",
    "    - Built-in check `v in l` returns `True` if value `v` is present in list `l`\n",
    "    - Add new venue to the list --- `l1 + l2` concatenates two lists into a single list "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "1ce56da8-0568-44b2-aa86-c6c619e1dba2",
   "metadata": {},
   "outputs": [],
   "source": [
    "venuelist = []\n",
    "for row in matchlist:\n",
    "    venue = row[0]  # Leftmost column\n",
    "    if not(venue in venuelist):\n",
    "        venuelist = venuelist + [venue]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8a7ee7b9-6bc5-4c0b-9d96-d4c0492aa053",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Chennai',\n",
       " 'Mohali',\n",
       " 'Kolkata',\n",
       " 'Jaipur',\n",
       " 'Ahmedabad',\n",
       " 'Bengaluru',\n",
       " 'Hyderabad',\n",
       " 'Lucknow',\n",
       " 'Visakhapatnam',\n",
       " 'Mumbai',\n",
       " 'Delhi',\n",
       " 'Dharamsala',\n",
       " 'Guwahati']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "venuelist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "5a7f7921-3c71-46a7-ae63-5593354cf9b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(venuelist)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50ac9eee-a9bf-454d-824e-ce68af11fa41",
   "metadata": {},
   "source": [
    "- Can instead use a *dictionary*\n",
    "    - A collection of key:value pairs\n",
    "    - Initialize to empty dictionary\n",
    "    - Check if venue already exists as a key\n",
    "        - Create a new key if the current venue is not a key, by assigning a value\n",
    "        - Value assigned to the key is unimportant here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f7e62548-51dd-4c1f-9223-23c369c888a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "venuedict = {}\n",
    "for row in matchlist:\n",
    "    venue = row[0]  # Leftmost column\n",
    "    if not(venue in venuedict.keys()):\n",
    "        venuedict[venue] = \"Something\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "a6a8762d-4186-403e-b4c4-f6ceffa39bb1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Chennai': 'Something',\n",
       " 'Mohali': 'Something',\n",
       " 'Kolkata': 'Something',\n",
       " 'Jaipur': 'Something',\n",
       " 'Ahmedabad': 'Something',\n",
       " 'Bengaluru': 'Something',\n",
       " 'Hyderabad': 'Something',\n",
       " 'Lucknow': 'Something',\n",
       " 'Visakhapatnam': 'Something',\n",
       " 'Mumbai': 'Something',\n",
       " 'Delhi': 'Something',\n",
       " 'Dharamsala': 'Something',\n",
       " 'Guwahati': 'Something'}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "venuedict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a86521fe-0894-4243-8a55-5380719c982b",
   "metadata": {},
   "source": [
    "- Can extract keys of a dictionary\n",
    "    - Similar to, but not quite a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "c348afda-a01c-4fda-8485-812dad911714",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['Chennai', 'Mohali', 'Kolkata', 'Jaipur', 'Ahmedabad', 'Bengaluru', 'Hyderabad', 'Lucknow', 'Visakhapatnam', 'Mumbai', 'Delhi', 'Dharamsala', 'Guwahati'])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "venuedict.keys()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc8dfa32-4f06-4d3d-b36c-623417c1616f",
   "metadata": {},
   "source": [
    "- By convention, Python assumes you mean `d.keys()` if you say `v in d` for a dictionary `d`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "17f81fe6-1457-410e-bd8a-8056c847a361",
   "metadata": {},
   "outputs": [],
   "source": [
    "venuedict2 = {}\n",
    "for row in matchlist:\n",
    "    venue = row[0]  # Leftmost column\n",
    "    if not(venue in venuedict2):  # Short form for venue in venuedict2.keys()\n",
    "        venuedict2[venue] = \"Something\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "5f4f0d1a-a547-4ebb-89f6-7656366268af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Chennai': 'Something',\n",
       " 'Mohali': 'Something',\n",
       " 'Kolkata': 'Something',\n",
       " 'Jaipur': 'Something',\n",
       " 'Ahmedabad': 'Something',\n",
       " 'Bengaluru': 'Something',\n",
       " 'Hyderabad': 'Something',\n",
       " 'Lucknow': 'Something',\n",
       " 'Visakhapatnam': 'Something',\n",
       " 'Mumbai': 'Something',\n",
       " 'Delhi': 'Something',\n",
       " 'Dharamsala': 'Something',\n",
       " 'Guwahati': 'Something'}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "venuedict2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7283613-8cf5-40af-81ce-957abddd752e",
   "metadata": {},
   "source": [
    "- Can also count the number of matches at each venue\n",
    "- For each key, maintain a counter\n",
    "    - When the key is created, initialize the counter to 1\n",
    "    - If the key already exists, increment the counter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "bb27be65-23fb-4148-8a46-c7f21be5348b",
   "metadata": {},
   "outputs": [],
   "source": [
    "venuedict3 = {}\n",
    "for row in matchlist:\n",
    "    venue = row[0]  # Leftmost column\n",
    "    if not(venue in venuedict3):  # Short form for venue in venuedict3.keys()\n",
    "        venuedict3[venue] = 1\n",
    "    else:\n",
    "        venuedict3[venue] = venuedict3[venue] + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "232c8279-c897-46f1-9232-26203837e1fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Chennai': 9,\n",
       " 'Mohali': 5,\n",
       " 'Kolkata': 7,\n",
       " 'Jaipur': 5,\n",
       " 'Ahmedabad': 8,\n",
       " 'Bengaluru': 7,\n",
       " 'Hyderabad': 6,\n",
       " 'Lucknow': 7,\n",
       " 'Visakhapatnam': 2,\n",
       " 'Mumbai': 7,\n",
       " 'Delhi': 5,\n",
       " 'Dharamsala': 2,\n",
       " 'Guwahati': 1}"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "venuedict3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa449823-fae8-471f-8f1a-d2354cdcb206",
   "metadata": {},
   "source": [
    "- Can invert the condition and exchange the two parts of the `if`\n",
    "- More readable if we avoid negated conditions!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ff50b0c6-e0af-4ef0-a871-5f46d391f7b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "venuedict4 = {}\n",
    "for row in matchlist:\n",
    "    venue = row[0]  # Leftmost column\n",
    "    if venue in venuedict4:  # Short form for venue in venuedict4.keys()\n",
    "        venuedict4[venue] = venuedict4[venue] + 1\n",
    "    else:\n",
    "        venuedict4[venue] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "5cc7a37a-a48e-4c83-8042-bfb6511f4266",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Chennai': 9,\n",
       " 'Mohali': 5,\n",
       " 'Kolkata': 7,\n",
       " 'Jaipur': 5,\n",
       " 'Ahmedabad': 8,\n",
       " 'Bengaluru': 7,\n",
       " 'Hyderabad': 6,\n",
       " 'Lucknow': 7,\n",
       " 'Visakhapatnam': 2,\n",
       " 'Mumbai': 7,\n",
       " 'Delhi': 5,\n",
       " 'Dharamsala': 2,\n",
       " 'Guwahati': 1}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "venuedict4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57a696da-6d6e-4b26-a3bd-b16890147559",
   "metadata": {},
   "source": [
    "## Which team played as Team 1 at maximum number of venues?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc855945-c424-421c-be77-fbe9062cdc9d",
   "metadata": {},
   "source": [
    "- Maintain a dictionary where keys are teams\n",
    "- For each team, associate a list of venues where it has played as Team 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "76f9f99b-1d80-4179-8e29-d822bbcdfa75",
   "metadata": {},
   "outputs": [],
   "source": [
    "teamvenuedict = {}\n",
    "for row in matchlist:\n",
    "    venue = row[0]\n",
    "    team1 = row[1]\n",
    "\n",
    "    # Update the dictionary for team1\n",
    "    if not (team1 in teamvenuedict):\n",
    "        teamvenuedict[team1] = [venue]\n",
    "    else:\n",
    "        if not (venue in teamvenuedict[team1]):\n",
    "            teamvenuedict[team1] = teamvenuedict[team1] + [venue]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3de1f8d-2019-4c50-aafe-e60810728ec1",
   "metadata": {},
   "source": [
    "- Again, may be more readable if we avoid (at least one) negated condition"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "9b2031d8-8000-4378-965c-373fcedbbdbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "teamvenuedict = {}\n",
    "for row in matchlist:\n",
    "    venue = row[0]\n",
    "    team1 = row[1]\n",
    "\n",
    "    # Update the dictionary for team1\n",
    "    if team1 in teamvenuedict:  # Update the value\n",
    "        if not (venue in teamvenuedict[team1]):\n",
    "            teamvenuedict[team1] = teamvenuedict[team1] + [venue] \n",
    "    else: # Create a new key\n",
    "         teamvenuedict[team1] = [venue]\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb796af3-18ae-4fd2-a2a2-bf97acc1f7cc",
   "metadata": {},
   "source": [
    "- Display the dictionary as a list of key-value pairs\n",
    "- `{ k1:v1, k2:v2, ..., km:vm }`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "e7592299-5c9b-4ebc-ab98-d5e99d928e14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RCB': ['Chennai',\n",
       "  'Bengaluru',\n",
       "  'Jaipur',\n",
       "  'Mumbai',\n",
       "  'Hyderabad',\n",
       "  'Dharamsala',\n",
       "  'Ahmedabad'],\n",
       " 'DC': ['Mohali', 'Visakhapatnam', 'Delhi', 'Kolkata'],\n",
       " 'KKR': ['Kolkata', 'Visakhapatnam', 'Chennai', 'Mumbai', 'Lucknow'],\n",
       " 'RR': ['Jaipur', 'Chennai', 'Guwahati'],\n",
       " 'GT': ['Ahmedabad', 'Bengaluru'],\n",
       " 'PK': ['Bengaluru', 'Mohali', 'Hyderabad'],\n",
       " 'CSK': ['Chennai', 'Hyderabad', 'Mumbai', 'Lucknow', 'Dharamsala'],\n",
       " 'SRH': ['Hyderabad',\n",
       "  'Ahmedabad',\n",
       "  'Mohali',\n",
       "  'Bengaluru',\n",
       "  'Delhi',\n",
       "  'Mumbai',\n",
       "  'Chennai'],\n",
       " 'LSG': ['Lucknow', 'Bengaluru', 'Kolkata', 'Hyderabad', 'Mumbai'],\n",
       " 'MI': ['Mumbai', 'Mohali', 'Jaipur', 'Lucknow']}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "teamvenuedict"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "50c9a71d-4319-422e-a193-ab719be18d70",
   "metadata": {},
   "source": [
    "- Run through the dictionary and record the team with max venues as Team 1\n",
    "- Keep track of team name and the number of venues"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e4523efc-7f2c-40e3-b28a-81894075240e",
   "metadata": {},
   "outputs": [],
   "source": [
    "maxteam = \"\"\n",
    "maxvenues = 0\n",
    "for team in teamvenuedict:\n",
    "    if len(teamvenuedict[team]) > maxvenues:\n",
    "        maxteam = team\n",
    "        maxvenues = len(teamvenuedict[team])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3216905-e789-44cc-9673-d6b6b6ebc338",
   "metadata": {},
   "source": [
    "- Can display more than one value at a time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "e34035cb-424c-49b4-a3bb-85570d9b77eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('RCB', 7)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maxteam, maxvenues"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a23cb96-f779-4473-b105-377d0c008af6",
   "metadata": {},
   "source": [
    "## Is winning the toss an advantage?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33bef569-4f29-4361-8acd-fcea66bf5f16",
   "metadata": {},
   "source": [
    "- Count the rows where the toss winner is the match winner\n",
    "- Check if the fraction of such rows is above a given threshold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "8638d470-870c-46a7-8ee4-171890022ba0",
   "metadata": {},
   "outputs": [],
   "source": [
    "threshold = 2/3\n",
    "count = 0\n",
    "tossandwin = 0\n",
    "for row in matchlist:\n",
    "    count = count + 1\n",
    "    tosswinner = row[3]\n",
    "    matchwinner = row[4]\n",
    "    if tosswinner == matchwinner: # Use == for equality check\n",
    "        tossandwin = tossandwin + 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8cea0060-5f71-4f5b-8533-79f89269ac2e",
   "metadata": {},
   "source": [
    "- Is the ratio above the threshold?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "0d8bfe47-512c-44ee-b9b2-7f81183f06c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tossandwin/count >= threshold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ccdb1160-3df0-4134-a93e-9f967d0a5d27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.43661971830985913"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tossandwin/count"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
