day1/Session-4.tex
author Madhusudan.C.S <madhusudancs@gmail.com>
Sun, 11 Oct 2009 16:51:43 +0530
changeset 94 8c92864c184b
parent 87 cd29428cd8f5
permissions -rwxr-xr-x
Almost last set of official solutions and final quiz.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
% Tutorial slides on Python.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
46
63704b5650f1 Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 45
diff changeset
     5
% Copyright (c) 2005-2009, Prabhu Ramachandran
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
\documentclass[14pt,compress]{beamer}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
%\documentclass[draft]{beamer}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
%\documentclass[compress,handout]{beamer}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
%\usepackage{pgfpages} 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
% Modified from: generic-ornate-15min-45min.de.tex
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
\mode<presentation>
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
{
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
  \usetheme{Warsaw}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
  \useoutertheme{split}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
  \setbeamercovered{transparent}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
\usepackage[english]{babel}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
\usepackage[latin1]{inputenc}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
%\usepackage{times}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
\usepackage[T1]{fontenc}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
% Taken from Fernando's slides.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
\usepackage{ae,aecompl}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
\usepackage{mathpazo,courier,euler}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
\usepackage[scaled=.95]{helvet}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
\definecolor{darkgreen}{rgb}{0,0.5,0}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
\usepackage{listings}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
\lstset{language=Python,
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
    36
    basicstyle=\ttfamily\bfseries,
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
    commentstyle=\color{red}\itshape,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
  stringstyle=\color{darkgreen},
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
  showstringspaces=false,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
  keywordstyle=\color{blue}\bfseries}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
    42
\usepackage{pgf}
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
    43
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
% Macros
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
\newcommand{\emphbar}[1]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
{\begin{beamercolorbox}[rounded=true]{emphbar} 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
      {#1}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
 \end{beamercolorbox}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
\newcounter{time}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
\setcounter{time}{0}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
\newcommand{\typ}[1]{\texttt{#1}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
%%% This is from Fernando's setup.
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
% \usepackage{color}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
% % Use and configure listings package for nicely formatted code
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
% \usepackage{listings}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
% \lstset{
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
%    language=Python,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
%    basicstyle=\small\ttfamily,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
%    commentstyle=\ttfamily\color{blue},
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
%    stringstyle=\ttfamily\color{orange},
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
%    showstringspaces=false,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
%    breaklines=true,
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
%    postbreak = \space\dots
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
% }
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
% Title page
46
63704b5650f1 Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 45
diff changeset
    78
\title[Basic Python]{Python:\\Advanced Python data structures, Functions and Debugging}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
46
63704b5650f1 Changed the copyright and Institute for all the sessions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 45
diff changeset
    80
\author[FOSSEE Team] {Asokan Pichai\\Prabhu Ramachandran}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
    83
\date[] {10, October 2009\\Day 1, Session 4}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
%\logo{\pgfuseimage{iitmlogo}}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
%% Delete this, if you do not want the table of contents to pop up at
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
%% the beginning of each subsection:
87
cd29428cd8f5 Added emphbar to boxes in Session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 86
diff changeset
    92
\AtBeginSection[]
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
{
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
  \begin{frame}<beamer>
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
    \frametitle{Outline}
87
cd29428cd8f5 Added emphbar to boxes in Session 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 86
diff changeset
    96
    \tableofcontents[currentsection,subsections]
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
  \end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
% If you wish to uncover everything in a step-wise fashion, uncomment
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
% the following command: 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
%\beamerdefaultoverlayspecification{<+->}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
% DOCUMENT STARTS
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
\begin{document}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
\begin{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
  \titlepage
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   115
\section{Advanced Data structures}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   117
\subsection{Dictionary}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   118
\begin{frame}{Dictionary}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
  \begin{itemize}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   120
    \item lists and tuples index: 0 \ldots n
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   121
    \item dictionaries index using strings
54
c3fe152b3539 Changed section titles for Session 2 and 4 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   122
    \item \typ{ d = \{ ``Hitchhiker's guide'' : 42, ``Terminator'' : ``I'll be back''\}}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   123
    \item \typ{d[``Terminator''] => ``I'll be back''}
54
c3fe152b3539 Changed section titles for Session 2 and 4 slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 50
diff changeset
   124
    \item aka associative array, key-value pair, hashmap, hashtable \ldots    
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   125
    \item what can be keys?
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
  \end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   129
\begin{frame}{Dictionary \ldots }
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
  \begin{itemize}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   131
    \item \alert{Unordered}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   132
      \begin{block}{Standard usage}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   133
        for key in dict:\\
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   134
        \ \ \ \ print dict[key]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   135
      \end{block}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   136
    \item \typ{d.keys()} returns a list
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   137
    \item can we have duplicate keys?
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
  \end{itemize}
45
3b8be02d94d4 Corrected inctime for Session 4 of Day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 29
diff changeset
   139
  \inctime{5}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   142
\begin{frame} {Problem Set 6.1}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   143
  \begin{description}
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   144
\item[6.1.1] You are given date strings of the form ``29, Jul 2009'', or ``4 January 2008''. In other words a number a string and another number, with a comma sometimes separating the items.Write a function that takes such a string and returns a tuple (yyyy, mm, dd) where all three elements are ints.
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   145
    \item[6.1.2] Count word frequencies in a file.
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   146
    \item[6.1.3] Find the most used Python keywords in your Python code (import keyword).
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   147
\end{description}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
45
3b8be02d94d4 Corrected inctime for Session 4 of Day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 29
diff changeset
   149
\inctime{10}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   152
\subsection{Set}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   154
  \frametitle{Set}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   155
    \begin{itemize}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   156
      \item Simplest container, mutable
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   157
      \item No ordering, no duplicates
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   158
      \item usual suspects: union, intersection, subset \ldots
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   159
      \item >, >=, <, <=, in, \ldots
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   160
    \end{itemize}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   161
    \begin{lstlisting}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   162
>>> f10 = set([1,2,3,5,8])
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   163
>>> p10 = set([2,3,5,7])
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   164
>>> f10|p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   165
set([1, 2, 3, 5, 7, 8])
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   166
>>> f10&p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   167
set([2, 3, 5])
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   168
>>> f10-p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   169
set([8, 1])
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   174
  \frametitle{Set}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   175
    \begin{lstlisting}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   176
>>> p10-f10, f10^p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   177
set([7]), set([1, 7, 8])
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   178
>>> set([2,3]) < p10
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
True
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   180
>>> set([2,3]) <= p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   181
True
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   182
>>> 2 in p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   183
True
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   184
>>> 4 in p10
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   185
False
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   186
>>> len(f10)
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   187
5
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
\end{lstlisting}
45
3b8be02d94d4 Corrected inctime for Session 4 of Day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 29
diff changeset
   189
\inctime{5}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   192
\begin{frame}
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   193
  \frametitle{Problem set 6.2}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   194
  \begin{description}
61
fc495fd7e84e Added tda.tex for day2 and compiled handout for day1.
Shantanu <shantanu@fossee.in>
parents: 59
diff changeset
   195
    \item[6.2.1] Given a dictionary of the names of students and their marks, identify how many duplicate marks are there? and what are these?
fc495fd7e84e Added tda.tex for day2 and compiled handout for day1.
Shantanu <shantanu@fossee.in>
parents: 59
diff changeset
   196
    \item[6.2.2] Given a string of the form ``4-7, 9, 12, 15'' find the numbers missing in this list for a given range.
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   197
\end{description}
45
3b8be02d94d4 Corrected inctime for Session 4 of Day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 29
diff changeset
   198
\inctime{10}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   201
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   202
\section{Functions Reloaded!}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   204
    \frametitle{Advanced functions}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
    \begin{itemize}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   206
        \item default args
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   207
        \item var args
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   208
        \item keyword args
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   209
        \item scope
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   210
        \item \typ{global}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
      \end{itemize}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   214
\subsection{Default arguments}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   216
  \frametitle{Functions: default arguments}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   217
  \small
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
  \begin{lstlisting}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   219
def ask_ok(prompt, complaint='Yes or no!'):
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
    while True:
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
        ok = raw_input(prompt)
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
        if ok in ('y', 'ye', 'yes'): 
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
            return True
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   224
        if ok in ('n', 'no', 'nop',
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   225
                  'nope'): 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
            return False
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
        print complaint
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   228
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   229
ask_ok('?')
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   230
ask_ok('?', '[Y/N]')
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
  \end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   234
\subsection{Keyword arguments}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
\begin{frame}[fragile]
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
  \frametitle{Functions: keyword arguments}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   237
  \small
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
  \begin{lstlisting}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   239
def ask_ok(prompt, complaint='Yes or no!'):
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   240
    while True:
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   241
        ok = raw_input(prompt)
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   242
        if ok in ('y', 'ye', 'yes'): 
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   243
            return True
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   244
        if ok in ('n', 'no', 'nop',
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   245
                  'nope'): 
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   246
            return False
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   247
        print complaint
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   249
ask_ok(prompt='?')
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   250
ask_ok(prompt='?', complaint='[y/n]')
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   251
ask_ok(complaint='[y/n]', prompt='?')
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
\end{lstlisting}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   253
\inctime{15} 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   256
\section{Functional programming}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   258
    \frametitle{Functional programming}
85
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   259
    \begin{itemize}
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   260
      \item What is the basic idea?
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   261
      \item Why is it interesting?
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   262
      \item \typ{map, reduce, filter}
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   263
      \item list comprehension
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   264
      \item generators
8ca53181bee6 Added quiz questions.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 65
diff changeset
   265
    \end{itemize}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   266
\end{frame}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   267
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   268
\subsection{List comprehensions}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   269
\begin{frame}[fragile]
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   270
    \frametitle{List Comprehensions}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   271
Lets say we want to squares of all the numbers from 1 to 100
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   272
    \begin{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   273
squares = []
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   274
for i in range(1, 100):
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   275
    squares.append(i * i)
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   276
    \end{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   277
    \begin{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   278
# list comprehension
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   279
squares = [i*i for i in range(1, 100)]
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   280
     \end{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   281
Which is more readable?
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   282
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   284
\begin{frame}[fragile]
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   285
    \frametitle{List Comprehensions}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   286
What if you had a more complex function?
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   287
Lets say we want squares of numbers from 1 to 100 ending in 1, 2, 5, 7 only
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   288
    \begin{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   289
squares = []
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   290
for i in range(1, 100):
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   291
    if i % 10 in [1, 2, 5, 7]:
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   292
        squares.append(i * i)
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   293
    \end{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   294
    \begin{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   295
# list comprehension
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   296
squares = [i*i for i in range(1, 100)
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   297
           if i % 10 in [1, 2, 5, 7]]
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   298
     \end{lstlisting}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   299
Which is more readable?
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   300
\inctime{15}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   301
\end{frame}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   302
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   303
\section{Debugging}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   304
\subsection{Errors and Exceptions}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   305
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   306
 \frametitle{Errors}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   307
 \begin{lstlisting}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   308
>>> while True print 'Hello world'
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   309
 \end{lstlisting}
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   310
\pause
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   311
  \begin{lstlisting}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   312
  File "<stdin>", line 1, in ?
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   313
    while True print 'Hello world'
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   314
                   ^
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   315
SyntaxError: invalid syntax
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   317
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   318
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   319
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   320
 \frametitle{Exceptions}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   321
 \begin{lstlisting}
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   322
>>> print spam
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   323
\end{lstlisting}
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   324
\pause
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   325
\begin{lstlisting}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   326
Traceback (most recent call last):
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   327
  File "<stdin>", line 1, in <module>
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   328
NameError: name 'spam' is not defined
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   329
\end{lstlisting}
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   330
\end{frame}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   331
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   332
\begin{frame}[fragile]
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   333
 \frametitle{Exceptions}
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   334
 \begin{lstlisting}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   335
>>> 1 / 0
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   336
\end{lstlisting}
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   337
\pause
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   338
\begin{lstlisting}
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   339
Traceback (most recent call last):
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   340
  File "<stdin>", line 1, in <module>
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   341
ZeroDivisionError: integer division 
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   342
or modulo by zero
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
\end{lstlisting}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   344
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   345
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   346
\subsection{Strategy}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   348
    \frametitle{Debugging effectively}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   349
    \begin{itemize}
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   350
        \item \kwrd{print} based strategy
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   351
        \item Process:
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
    \end{itemize}
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   353
\pgfimage[interpolate=true,width=5cm,height=5cm]{DebugginDiagram.png}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   354
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   355
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   356
\begin{frame}[fragile]
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   357
    \frametitle{Debugging effectively}
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   358
    \begin{itemize}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   359
      \item Using \typ{\%debug} in IPython
59
9aac0f128482 Removed slides on pdb from session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 54
diff changeset
   360
    \end{itemize}
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   361
\end{frame}
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   362
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   363
\begin{frame}[fragile]
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   364
\frametitle{Debugging in IPython}
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   365
\small
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   366
\begin{lstlisting}
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   367
In [1]: import mymodule
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   368
In [2]: mymodule.test()
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   369
---------------------------------------------
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   370
NameError   Traceback (most recent call last)
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   371
<ipython console> in <module>()
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   372
mymodule.py in test()
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   373
      1 def test():
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   374
----> 2     print spam
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   375
NameError: global name 'spam' is not defined
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   376
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   377
In [3]: %debug
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   378
> mymodule.py(2)test()
63
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   379
      0     print spam
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   380
ipdb> 
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   381
\end{lstlisting}
f5eac04a00fe Added debugging process diagram to Session 4 of day 1.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 59
diff changeset
   382
\inctime{15} 
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   383
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   384
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   385
\subsection{Exercise}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   386
\begin{frame}[fragile]
29
8121d3ea15b5 Completed slides for session 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 5
diff changeset
   387
\frametitle{Debugging: Exercise}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   388
\small
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   389
\begin{lstlisting}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   390
import keyword
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   391
f = open('/path/to/file')
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   392
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   393
freq = {}
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   394
for line in f:
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   395
    words = line.split()
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   396
    for word in words:
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   397
        key = word.strip(',.!;?()[]: ')
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   398
        if keyword.iskeyword(key):
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   399
            value = freq[key]
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   400
            freq[key] = value + 1
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   401
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   402
print freq
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   403
\end{lstlisting}
50
aabaf8ec0a08 Added What did we learn at the end of each session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 49
diff changeset
   404
\inctime{10}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   405
\end{frame}
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   406
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   407
\begin{frame}
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   408
  \frametitle{What did we learn?}
50
aabaf8ec0a08 Added What did we learn at the end of each session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 49
diff changeset
   409
  \begin{itemize}
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   410
    \item Dictionaries
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   411
    \item Sets
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   412
    \item Default and keyword arguments
50
aabaf8ec0a08 Added What did we learn at the end of each session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 49
diff changeset
   413
    \item Functional Programming, list comprehensions
aabaf8ec0a08 Added What did we learn at the end of each session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 49
diff changeset
   414
    \item Errors and Exceptions in Python
86
f657495cf8b2 Final set of changes.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 85
diff changeset
   415
    \item Debugging: \%debug in IPython
50
aabaf8ec0a08 Added What did we learn at the end of each session.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 49
diff changeset
   416
  \end{itemize}
49
2adb90f9e287 Added what did we learn to all slides and reworked on Session 2 and 4.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 46
diff changeset
   417
\end{frame}
5
838cedef5e9d Added 4 tex slides for 4 sessions of Day 1 of the workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   418
\end{document}