{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6b4fce18-128e-441d-9040-7d738b1ac1c8",
   "metadata": {},
   "source": [
    "## PDSP 2025, Assignment 1\n",
    "### 6 Sep 2025, due 12 Sep 2025"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b5584388-466e-406b-bf3c-a1ec279d8646",
   "metadata": {},
   "source": [
    "## Instructions\n",
    "\n",
    "- All questions below use a table with IPL 2025 data converted to a list of tuples. The data is in the cells following the Questions.\n",
    "\n",
    "- Write Python function(s) for each question, as specified.\n",
    "\n",
    "- You may (and probably should) write auxiliary helper functions as needed.\n",
    "\n",
    "- Submit your solution through Moodle as a single Python notebook with solutions to all the questions.\n",
    "\n",
    "    - Add documentation to separate out the solutions into clearly marked areas within the notebook, and explain at a high level what your code is doing\n",
    "    - Show some sample executions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c96386e-4aad-4b0a-83fb-cdd2e7ea81c8",
   "metadata": {},
   "source": [
    "## Questions"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46edd6e8-91bb-4ef1-91ae-9a037337cac9",
   "metadata": {},
   "source": [
    "1. Which team had the highest winning percentage?\n",
    "    - Write a function `max_win_percentage(m)` that takes a list of matches and returns the team that won the largest fraction of mathes that it played."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "006d8551-ffa8-47c4-b659-1a493e0acefa",
   "metadata": {},
   "source": [
    "2. Is it better to bowl first or bat first?\n",
    "    - Write a function `bowl_first_win(m)` that takes a list of matches and returns the fraction of matches won by the team bowling first."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7097c6ad-de31-43f7-bd9b-cf65a21bb45a",
   "metadata": {},
   "source": [
    "3. Which team(s) batted first most often?\n",
    "    - Write a function `bat_first_max(m)` that takes a list of matches and returns the team(s) that batted first most often, as a list."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6049dc7a-5cde-4972-9820-de6524315a67",
   "metadata": {},
   "source": [
    "4. If the match goes into the final over (number of balls left is less than 6), which team has an advantage -- the team that batted first or the team that batted second?\n",
    "    - Write a function `last_over_favours(m)` that takes a list of matches and returns `1` if the team batting first has an advantage and `2` if the team batting second has an advantage."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a0e3f87-22ec-4f80-9cb3-a67e4493edf3",
   "metadata": {},
   "source": [
    "5. Which venue(s) most favour the team batting second?\n",
    "    - Write a function `best_chasing_venue(m)` that takes a list of matches and returns the venue(s) that most favour the team batting second, as a list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "879ec57a-2e55-4547-9e93-fbea876fdcbf",
   "metadata": {},
   "source": [
    "## IPL 2025 data\n",
    "- Each match is a tuple of columns \n",
    "- `(Venue, Team 1, Team 2, Toss winner, Toss Decision, Win by runs, Win by wickets, Balls left, Player of the match)`\n",
    "- When the team batting first wins the match, `Win by runs` denotes the winning margin\n",
    "- When the team batting second wins the match, `Win by wickets` denotes the winning margin\n",
    "- There may be some anomalous rows due to super overs etc. You can deal with these in any way you wish, but document the choices that you have made."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "90dd963d-bf0a-4fa5-963d-1f79a418243d",
   "metadata": {},
   "outputs": [],
   "source": [
    "matchlist = [\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"RCB\",\"RCB\",\"Bowl\",\"\",7,22,\"Krunal Pandya\"),\n",
    "(\"Rajiv Gandhi International Stadium, Hyderabad\",\"SRH\",\"RR\",\"RR\",\"Bowl\",44,\"\",0,\"Ishan Kishan\"),\n",
    "(\"MA Chidambaram Stadium, Chennai\",\"CSK\",\"MI\",\"CSK\",\"Bowl\",\"\",4,5,\"Noor Ahmad\"),\n",
    "(\"ACA-VDCA Cricket Stadium, Vishakhapatnam\",\"DC\",\"LSG\",\"DC\",\"Bowl\",\"\",1,3,\"Ashutosh Sharma\"),\n",
    "(\"Narendra Modi Stadium, Ahmedabad\",\"GT\",\"PBKS\",\"GT\",\"Bowl\",11,\"\",0,\"Shreyas Iyer\"),\n",
    "(\"Barsapara Stadium, Guwahati\",\"RR\",\"KKR\",\"KKR\",\"Bowl\",\"\",8,15,\"Quinton de Kock\"),\n",
    "(\"Rajiv Gandhi International Stadium, Hyderabad\",\"SRH\",\"LSG\",\"LSG\",\"Bowl\",\"\",5,23,\"Shardul Thakur\"),\n",
    "(\"MA Chidambaram Stadium, Chennai\",\"CSK\",\"RCB\",\"CSK\",\"Bowl\",50,\"\",0,\"Rajat Patidar\"),\n",
    "(\"Narendra Modi Stadium, Ahmedabad\",\"GT\",\"MI\",\"MI\",\"Bowl\",36,\"\",0,\"Prasidh Krishna\"),\n",
    "(\"ACA-VDCA Cricket Stadium, Vishakhapatnam\",\"DC\",\"SRH\",\"SRH\",\"Bat\",\"\",7,24,\"Mitchell Starc\"),\n",
    "(\"Barsapara Stadium, Guwahati\",\"RR\",\"CSK\",\"CSK\",\"Bowl\",6,\"\",0,\"Nitish Rana\"),\n",
    "(\"Wankhede Stadium, Mumbai\",\"MI\",\"KKR\",\"MI\",\"Bowl\",\"\",8,43,\"Ashwani Kumar\"),\n",
    "(\"Ekana Cricket Stadium, Lucknow\",\"LSG\",\"PBKS\",\"PBKS\",\"Bowl\",\"\",8,22,\"Prabhsimran Singh\"),\n",
    "(\"M. Chinnaswamy Stadium, Bangalore\",\"RCB\",\"GT\",\"GT\",\"Bowl\",\"\",8,13,\"Mohammed Siraj\"),\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"SRH\",\"SRH\",\"Bowl\",80,\"\",20,\"Vaibhav Arora\"),\n",
    "(\"Ekana Cricket Stadium, Lucknow\",\"LSG\",\"MI\",\"MI\",\"Bowl\",12,\"\",0,\"Digvesh Singh\"),\n",
    "(\"MA Chidambaram Stadium, Chennai\",\"CSK\",\"DC\",\"DC\",\"Bat\",25,\"\",0,\"KL Rahul\"),\n",
    "(\"New PCA Cricket Stadium, Mullanpur\",\"PBKS\",\"RR\",\"PBKS\",\"Bowl\",50,\"\",0,\"Jofra Archer\"),\n",
    "(\"Rajiv Gandhi International Stadium, Hyderabad\",\"SRH\",\"GT\",\"GT\",\"Bowl\",\"\",7,20,\"Mohammed Siraj\"),\n",
    "(\"Wankhede Stadium, Mumbai\",\"MI\",\"RCB\",\"MI\",\"Bowl\",12,\"\",0,\"Rajat Patidar\"),\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"LSG\",\"KKR\",\"Bowl\",4,\"\",0,\"Nicholas Pooran\"),\n",
    "(\"New PCA Cricket Stadium, Mullanpur\",\"PBKS\",\"CSK\",\"PBKS\",\"Bat\",18,\"\",0,\"Priyansh Arya\"),\n",
    "(\"Narendra Modi Stadium, Ahmedabad\",\"GT\",\"RR\",\"RR\",\"Bowl\",58,\"\",4,\"Sai Sudarshan\"),\n",
    "(\"M. Chinnaswamy Stadium, Bangalore\",\"RCB\",\"DC\",\"DC\",\"Bowl\",\"\",6,13,\"KL Rahul\"),\n",
    "(\"MA Chidambaram Stadium, Chennai\",\"CSK\",\"KKR\",\"KKR\",\"Bowl\",\"\",8,59,\"Sunil Narine\"),\n",
    "(\"Ekana Cricket Stadium, Lucknow\",\"LSG\",\"GT\",\"LSG\",\"Bowl\",\"\",6,3,\"Aiden Markram\"),\n",
    "(\"Rajiv Gandhi International Stadium, Hyderabad\",\"SRH\",\"PBKS\",\"PBKS\",\"Bat\",\"\",8,9,\"Abhishek Sharma\"),\n",
    "(\"Sawai Mansingh Stadium, Jaipur\",\"RR\",\"RCB\",\"RCB\",\"Bowl\",\"\",9,15,\"Phil Salt\"),\n",
    "(\"Arun Jaitley Stadium, Delhi\",\"DC\",\"MI\",\"DC\",\"Bowl\",12,\"\",6,\"Karn Sharma\"),\n",
    "(\"Ekana Cricket Stadium, Lucknow\",\"LSG\",\"CSK\",\"CSK\",\"Bowl\",\"\",5,3,\"MS Dhoni\"),\n",
    "(\"New PCA Cricket Stadium, Mullanpur\",\"PBKS\",\"KKR\",\"PBKS\",\"Bat\",16,\"\",29,\"Yuzvendra Chahal\"),\n",
    "(\"Arun Jaitley Stadium, Delhi\",\"DC\",\"RR\",\"RR\",\"Bowl\",\"super over\",\"super over\",0,\"Mitchell Starc\"),\n",
    "(\"Wankhede Stadium, Mumbai\",\"MI\",\"SRH\",\"MI\",\"Bowl\",\"\",4,11,\"Will Jacks\"),\n",
    "(\"M. Chinnaswamy Stadium, Bangalore\",\"RCB\",\"PBKS\",\"PBKS\",\"Bowl\",\"\",5,11,\"Tim David\"),\n",
    "(\"Narendra Modi Stadium, Ahmedabad\",\"GT\",\"DC\",\"GT\",\"Bowl\",\"\",7,4,\"Jos Buttler\"),\n",
    "(\"Sawai Mansingh Stadium, Jaipur\",\"RR\",\"LSG\",\"LSG\",\"Bat\",2,\"\",0,\"Avesh Khan\"),\n",
    "(\"New PCA Cricket Stadium, Mullanpur\",\"PBKS\",\"RCB\",\"RCB\",\"Bowl\",\"\",7,7,\"Virat Kohli\"),\n",
    "(\"Wankhede Stadium, Mumbai\",\"MI\",\"CSK\",\"MI\",\"Bowl\",\"\",9,26,\"Rohit Sharma\"),\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"GT\",\"KKR\",\"Bowl\",39,\"\",0,\"Shubman Gill\"),\n",
    "(\"Ekana Cricket Stadium, Lucknow\",\"LSG\",\"DC\",\"DC\",\"Bowl\",\"\",8,13,\"Mukesh Kumar\"),\n",
    "(\"Rajiv Gandhi International Stadium, Hyderabad\",\"SRH\",\"MI\",\"SRH\",\"Bowl\",\"\",7,26,\"Trent Boult\"),\n",
    "(\"M. Chinnaswamy Stadium, Bangalore\",\"RCB\",\"RR\",\"RR\",\"Bowl\",11,\"\",0,\"Josh Hazlewood\"),\n",
    "(\"MA Chidambaram Stadium, Chennai\",\"CSK\",\"SRH\",\"SRH\",\"Bowl\",\"\",5,8,\"Harshal Patel\"),\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"PBKS\",\"PBKS\",\"Bat\",\"\",\"\",114,\"\"),\n",
    "(\"Wankhede Stadium, Mumbai\",\"MI\",\"LSG\",\"LSG\",\"Bowl\",54,\"\",0,\"Will Jacks\"),\n",
    "(\"Arun Jaitley Stadium, Delhi\",\"DC\",\"RCB\",\"RCB\",\"Bowl\",\"\",6,9,\"Krunal Pandya\"),\n",
    "(\"Sawai Mansingh Stadium, Jaipur\",\"RR\",\"GT\",\"RR\",\"Bowl\",\"\",8,25,\"Vaibhav Suryavanshi\"),\n",
    "(\"Arun Jaitley Stadium, Delhi\",\"DC\",\"KKR\",\"DC\",\"Bowl\",14,\"\",0,\"Sunil Narine\"),\n",
    "(\"MA Chidambaram Stadium, Chennai\",\"CSK\",\"PBKS\",\"PBKS\",\"Bowl\",\"\",4,2,\"Shreyas Iyer\"),\n",
    "(\"Sawai Mansingh Stadium, Jaipur\",\"RR\",\"MI\",\"RR\",\"Bowl\",100,\"\",23,\"Ryan Rickelton\"),\n",
    "(\"Narendra Modi Stadium, Ahmedabad\",\"GT\",\"SRH\",\"SRH\",\"Bowl\",38,\"\",0,\"Prasidh Krishna\"),\n",
    "(\"M. Chinnaswamy Stadium, Bangalore\",\"RCB\",\"CSK\",\"CSK\",\"Bowl\",2,\"\",0,\"Romario Shepherd\"),\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"RR\",\"KKR\",\"Bat\",1,\"\",0,\"Andre Russell\"),\n",
    "(\"HPCA Stadium, Dharamshala\",\"PBKS\",\"LSG\",\"LSG\",\"Bowl\",37,\"\",0,\"Prabhsimran Singh\"),\n",
    "(\"Wankhede Stadium, Mumbai\",\"MI\",\"GT\",\"GT\",\"Bowl\",\"\",3,0,\"Shubman Gill\"),\n",
    "(\"Eden Gardens, Kolkata\",\"KKR\",\"CSK\",\"KKR\",\"Bat\",\"\",2,2,\"Noor Ahmad\"),\n",
    "(\"Sawai Mansingh Stadium, Jaipur\",\"RR\",\"PBKS\",\"PBKS\",\"Bat\",10,\"\",0,\"Harpreet Brar\"),\n",
    "(\"Arun Jaitley Stadium, Delhi\",\"DC\",\"GT\",\"GT\",\"Bowl\",\"\",10,6,\"Sai Sudarshan\")\n",
    "]"
   ]
  }
 ],
 "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
}
