day2/session2.tex
author Puneeth Chaganti <punchagan@fossee.in>
Wed, 28 Oct 2009 17:35:41 +0530
changeset 243 33ede079857d
parent 239 8953675dc056
child 251 457b67834245
permissions -rw-r--r--
Added pos.txt file.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
%Tutorial slides on Python.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
% Copyright (c) 2005-2009, Prabhu Ramachandran
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
\documentclass[14pt,compress]{beamer}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
%\documentclass[draft]{beamer}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
%\documentclass[compress,handout]{beamer}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
%\usepackage{pgfpages} 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
% Modified from: generic-ornate-15min-45min.de.tex
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
\mode<presentation>
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
{
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
  \usetheme{Warsaw}
239
8953675dc056 Added slide numbers.
Puneeth Chaganti <punchagan@fossee.in>
parents: 228
diff changeset
    18
  \useoutertheme{infolines}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
  \setbeamercovered{transparent}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    21
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    22
\usepackage[english]{babel}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    23
\usepackage[latin1]{inputenc}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    24
%\usepackage{times}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    25
\usepackage[T1]{fontenc}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    26
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    27
% Taken from Fernando's slides.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    28
\usepackage{ae,aecompl}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    29
\usepackage{mathpazo,courier,euler}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    30
\usepackage[scaled=.95]{helvet}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    31
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    32
\definecolor{darkgreen}{rgb}{0,0.5,0}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    33
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    34
\usepackage{listings}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    35
\lstset{language=Python,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    36
    basicstyle=\ttfamily\bfseries,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    37
    commentstyle=\color{red}\itshape,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    38
  stringstyle=\color{darkgreen},
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    39
  showstringspaces=false,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    40
  keywordstyle=\color{blue}\bfseries}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    41
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    42
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    43
% Macros
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    44
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    45
\newcommand{\emphbar}[1]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    46
{\begin{beamercolorbox}[rounded=true]{emphbar} 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    47
      {#1}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    48
 \end{beamercolorbox}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    49
}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    50
\newcounter{time}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    51
\setcounter{time}{0}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    52
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    53
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    54
\newcommand{\typ}[1]{\texttt{#1}}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    55
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    56
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    57
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    58
%%% This is from Fernando's setup.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    59
% \usepackage{color}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    60
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    61
% % Use and configure listings package for nicely formatted code
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    62
% \usepackage{listings}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    63
% \lstset{
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    64
%    language=Python,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    65
%    basicstyle=\small\ttfamily,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    66
%    commentstyle=\ttfamily\color{blue},
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    67
%    stringstyle=\ttfamily\color{orange},
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    68
%    showstringspaces=false,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    69
%    breaklines=true,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    70
%    postbreak = \space\dots
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    71
% }
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    72
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    73
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    75
% Title page
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    76
\title[Basic Python]{Python:\\A formal approach}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    77
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    78
\author[FOSSEE Team] {The FOSSEE Group}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    79
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    80
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    81
\date[] {1, November 2009\\Day 2, Session 2}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    83
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    84
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    85
%\logo{\pgfuseimage{iitmlogo}}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    86
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    87
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    88
%% Delete this, if you do not want the table of contents to pop up at
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    89
%% the beginning of each subsection:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    90
\AtBeginSubsection[]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    91
{
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    92
  \begin{frame}<beamer>
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    93
    \frametitle{Outline}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    94
    \tableofcontents[currentsection,currentsubsection]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    95
  \end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    96
}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    97
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    98
\AtBeginSection[]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    99
{
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   100
  \begin{frame}<beamer>
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   101
    \frametitle{Outline}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   102
    \tableofcontents[currentsection,currentsubsection]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   103
  \end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   104
}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   105
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   106
% If you wish to uncover everything in a step-wise fashion, uncomment
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   107
% the following command: 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   108
%\beamerdefaultoverlayspecification{<+->}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   109
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   110
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   111
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   112
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   113
% DOCUMENT STARTS
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   114
\begin{document}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   115
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   116
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   117
  \titlepage
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   118
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   119
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   120
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   121
  \frametitle{Outline}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   122
  \tableofcontents
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   123
  % You might wish to add the option [pausesections]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   124
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   125
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   126
\section{Data structures}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   127
\subsection{Lists}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   128
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   129
  \frametitle{Lists}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   130
\begin{block}{We already know that}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   131
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   132
num = [1, 2, 3, 4, 5, 6, 7, 8]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   133
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   134
\centerline{is a list}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   135
\end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   136
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   137
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   138
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   139
  \frametitle{Lists: methods}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   140
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   141
In []: num.reverse()
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   142
In []: num
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   143
Out[]: [8, 7, 6, 5, 4, 3, 2, 1]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   144
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   145
In []: num.extend([0, -1, -2])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   146
In []: num
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   147
Out[]: [8, 7, 6, 5, 4, 3, 2, 1, 0, -1]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   148
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   149
In []: num.remove(0)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   150
In []: num
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   151
Out[]: [8, 7, 6, 5, 4, 3, 2, 1, -1]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   152
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   153
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   154
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   155
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   156
\frametitle{List containership}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   157
\begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   158
In []: a = 8
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   159
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   160
In []: a in num
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   161
Out[]: True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   162
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   163
In []: b = 10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   164
In []: b in num
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   165
Out[]: False
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   166
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   167
In []: b not in num
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   168
Out[]: True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   169
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   170
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   171
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   172
\subsection{Tuples}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   173
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   174
\frametitle{Tuples: Immutable lists}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   175
\begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   176
In []: t = (1, 2, 3, 4, 5, 6, 7, 8)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   177
In []: t[0] + t[3] + t[-1]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   178
Out[]: 13
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   179
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   180
\begin{block}{Note:}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   181
\begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   182
  \item Tuples are immutable - cannot be changed
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   183
\end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   184
\end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   185
  \inctime{10}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   186
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   187
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   188
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   189
  {A classic problem}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   190
  \begin{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   191
    {Interchange values}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   192
    How to interchange values of two variables? 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   193
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   194
  \pause
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   195
  \begin{block}{Note:}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   196
    This Python idiom works for all types of variables.\\
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   197
They need not be of the same type!
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   198
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   199
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   200
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   201
\subsection{Dictionaries}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   202
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   203
  \frametitle{Dictionaries: Recall}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   204
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   205
In []: player = {'Mat': 134,'Inn': 233,
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   206
          'Runs': 10823, 'Avg': 52.53}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   207
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   208
In []: player['Avg']
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   209
Out[]: 52.530000000000001
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   210
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   211
  \begin{block}{Note!}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   212
    Duplicate keys are not allowed!\\
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
    Dictionaries are iterable through keys.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
\begin{frame} {Problem Set 2.1: Problem 2.1.1}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   218
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.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   219
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   221
\subsection{Set}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
  \frametitle{Set}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
    \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
      \item Simplest container, mutable
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
      \item No ordering, no duplicates
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
      \item usual suspects: union, intersection, subset \ldots
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   228
      \item >, >=, <, <=, in, \ldots
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   229
    \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   230
    \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   231
>>> f10 = set([1,2,3,5,8])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   232
>>> p10 = set([2,3,5,7])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   233
>>> f10|p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   234
set([1, 2, 3, 5, 7, 8])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   235
>>> f10&p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   236
set([2, 3, 5])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   237
>>> f10-p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   238
set([8, 1])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   239
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   240
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   241
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   242
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   243
  \frametitle{Set}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   244
    \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   245
>>> p10-f10, f10^p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   246
set([7]), set([1, 7, 8])
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   247
>>> set([2,3]) < p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   248
True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
>>> set([2,3]) <= p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   251
>>> 2 in p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   253
>>> 4 in p10
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
False
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   255
>>> len(f10)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   256
5
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   257
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   258
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   259
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   260
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   261
  \frametitle{Problem set 2.2}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   262
  \begin{description}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   263
    \item[2.2.1] Given a dictionary of the names of students and their marks, identify how many duplicate marks are there? and what are these?
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   264
    \item[2.2.2] Given a string of the form ``4-7, 9, 12, 15'' find the numbers missing in this list for a given range.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   265
\end{description}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   266
\inctime{15}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   267
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   268
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   269
\section{Functions}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   270
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   271
  \frametitle{Functions}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   272
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   273
    \item \kwrd{def} - keyword to define a function
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   274
    \item Arguments are local to a function
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   275
    \item Docstrings are important!
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   276
    \item Functions can return multiple values
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   277
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   278
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   279
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   280
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   281
  \frametitle{Functions: example}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   282
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   283
def signum( r ):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   284
    """returns 0 if r is zero
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   285
    -1 if r is negative
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   286
    +1 if r is positive"""
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   287
    if r < 0:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   288
        return -1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   289
    elif r > 0:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   290
        return 1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   291
    else:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   292
        return 0
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   295
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   296
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
  {What does this function do?}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   298
\begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   299
def what( n ):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   300
    i = 1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   301
    while i * i < n:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   302
        i += 1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
    return i * i == n, i
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   304
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   305
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   306
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   307
\subsection{Default arguments}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   308
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   309
  \frametitle{Functions: default arguments}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   310
  \small
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   311
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   312
def ask_ok(prompt, complaint='Yes or no!'):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   313
    while True:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   314
        ok = raw_input(prompt)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   315
        if ok in ('y', 'ye', 'yes'): 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
            return True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   317
        if ok in ('n', 'no', 'nop',
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   318
                  'nope'): 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   319
            return False
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   320
        print complaint
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   321
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   322
ask_ok('?')
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   323
ask_ok('?', '[Y/N]')
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   324
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   325
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   326
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   327
\subsection{Built-in functions}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   328
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   329
  {Before writing a function}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   330
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   331
      \item Variety of builtin functions are available
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   332
      \item \typ{abs, any, all, len, max, min}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   333
      \item \typ{pow, range, sum, type}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   334
      \item Refer here:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   335
          \url{http://docs.python.org/library/functions.html}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   336
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   337
  \inctime{10} 
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   338
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   339
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   340
\subsection{Exercises}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   341
\begin{frame}{Problem set 3: Problem 3.1}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   342
  Write a function to return the gcd of two numbers.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   344
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   345
\begin{frame}{Problem 3.2}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
Write a program to print all primitive pythagorean triads (a, b, c) where a, b are in the range 1---100 \\
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
A pythagorean triad $(a,b,c)$ has the property $a^2 + b^2 = c^2$.\\By primitive we mean triads that do not `depend' on others. For example, (4,3,5) is a variant of (3,4,5) and hence is not primitive. And (10,24,26) is easily derived from (5,12,13) and is also not primitive.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   348
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   349
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   350
\begin{frame}{Problem 3.3}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   351
  Write a program that generates a list of all four digit numbers that have all their digits even and are perfect squares.\newline\\\emph{For example, the output should include 6400 but not 8100 (one digit is odd) or 4248 (not a perfect square).}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
\inctime{15}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   353
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   354
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   355
\section{Modules}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   356
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   357
    {Modules}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   358
\begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   359
>>> sqrt(2)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   360
Traceback (most recent call last):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   361
  File "<stdin>", line 1, in <module>
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   362
NameError: name 'sqrt' is not defined
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   363
>>> import math        
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   364
>>> math.sqrt(2)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   365
1.4142135623730951
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   366
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   367
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   368
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   369
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   370
    {Modules}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   371
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   372
    \item The \kwrd{import} keyword ``loads'' a module
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   373
    \item One can also use:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   374
      \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   375
>>> from math import sqrt
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   376
>>> from math import *
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   377
      \end{lstlisting}    
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   378
    \item What is the difference?
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   379
    \item \alert{Use the latter only in interactive mode}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   380
    \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   381
  \emphbar{Package hierarchies}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   382
      \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   383
>>> from os.path import exists
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   384
      \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   385
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   386
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   387
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   388
  \frametitle{Modules: Standard library}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   389
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   390
  \item Very powerful, ``Batteries included''
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   391
  \item Some standard modules:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   392
    \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   393
    \item Math: \typ{math}, \typ{random}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   394
    \item Internet access: \typ{urllib2}, \typ{smtplib}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   395
    \item System, Command line arguments: \typ{sys}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   396
    \item Operating system interface: \typ{os}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   397
    \item Regular expressions: \typ{re}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   398
    \item Compression: \typ{gzip}, \typ{zipfile}, and \typ{tarfile}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   399
    \item And a whole lot more!
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   400
    \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   401
  \item Check out the Python Library reference:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   402
    \url{http://docs.python.org/library/}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   403
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   404
\inctime{5}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   405
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   406
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   407
\section{Coding Style}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   408
\begin{frame}{Readability and Consistency}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   409
    \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   410
        \item Readability Counts!\\Code is read more often than its written.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   411
        \item Consistency!
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   412
        \item Know when to be inconsistent.
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   413
      \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   414
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   415
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   416
\begin{frame}[fragile] \frametitle{A question of good style}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   417
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   418
    amount = 12.68
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   419
    denom = 0.05
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   420
    nCoins = round(amount/denom)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   421
    rAmount = nCoins * denom
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   422
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   423
  \pause
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   424
  \begin{block}{Style Rule \#1}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   425
    Naming is 80\% of programming
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   426
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   427
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   428
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   429
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   430
  \frametitle{Code Layout}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   431
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   432
        \item Indentation
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   433
        \item Tabs or Spaces??
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   434
        \item Maximum Line Length
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   435
        \item Blank Lines
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   436
        \item Encodings
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   437
   \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   438
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   439
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   440
\begin{frame}{Whitespaces in Expressions}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   441
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   442
        \item When to use extraneous whitespaces??
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   443
        \item When to avoid extra whitespaces??
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   444
        \item Use one statement per line
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   445
   \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   446
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   447
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   448
\begin{frame}{Comments}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   449
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   450
        \item No comments better than contradicting comments
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   451
        \item Block comments
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   452
        \item Inline comments
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   453
   \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   454
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   455
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   456
\begin{frame}{Docstrings}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   457
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   458
        \item When to write docstrings?
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   459
        \item Ending the docstrings
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   460
        \item One liner docstrings
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   461
   \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   462
More information at PEP8: http://www.python.org/dev/peps/pep-0008/
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   463
\inctime{5}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   464
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   465
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   466
\section{Objects}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   467
\begin{frame}{Objects in general}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   468
    \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   469
        \item What is an Object? (Types and classes)
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   470
        \item identity
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   471
        \item type
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   472
        \item method
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   473
      \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   474
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   475
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   476
\begin{frame}{Almost everything is an Object!}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   477
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   478
    \item \typ{list}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   479
    \item \typ{tuple}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   480
    \item \typ{string}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   481
    \item \typ{dictionary}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   482
    \item \typ{function}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   483
    \item Of course, user defined class objects!
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   484
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   485
\end {frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   486
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   487
\begin{frame}{Using Objects}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   488
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   489
    \item Creating Objects: Initialization
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   490
    \item Object Manipulation: Object methods and ``.'' operator
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   491
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   492
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   493
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   494
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   495
  \frametitle{Objects provide consistency}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   496
  \small
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   497
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   498
for element in (1, 2, 3):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   499
    print element
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   500
for key in {'one':1, 'two':2}:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   501
    print key
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   502
for char in "123":
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   503
    print char
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   504
for line in open("myfile.txt"):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   505
    print line
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   506
for line in urllib2.urlopen('http://site.com'):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   507
    print line
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   508
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   509
\inctime{10}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   510
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   511
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   512
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   513
  \frametitle{What did we learn?}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   514
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   515
    \item Lists, Tuples, Dictionaries, Sets: creation and manipulation
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   516
    \item More about functions
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   517
    \item Coding style
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   518
    \item Objects: creation and manipulation
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   519
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   520
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   521
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   522
\end{document}