day2/session2.tex
author Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
Mon, 21 Jun 2010 00:49:03 -0400
branchscipy2010
changeset 412 ca04d463c573
parent 393 b7d2222b60a8
child 424 2ab009c9f80a
permissions -rw-r--r--
ENH: Enhanced the problem set building on the image handing and arrays. Illustrated dtypes, casting and their importance along with an example using RGBA images. Also introduce edge detection.
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
%
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
     4
% Author: FOSSEE 
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
     5
% Copyright (c) 2009, FOSSEE, IIT Bombay
228
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
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
    54
\newcommand{\typ}[1]{\lstinline{#1}}
228
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
251
457b67834245 Fixed typos and hanging words in Session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 239
diff changeset
    76
\title[Basic Python]{Python language: Data structures and functions}
228
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}
389
aa392117454f Changed dates for MVIT workshop.
Puneeth Chaganti <punchagan@gmail.com>
parents: 385
diff changeset
    81
\date[] {1 May, 2010\\Day 2, Session 2}
228
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
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   126
\section{Control flow}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   127
\subsection{Basic Looping}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   128
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   129
  \frametitle{\typ{while}}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   130
\begin{block}{Example: Fibonacci series}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   131
  Sum of previous two elements defines the next
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   132
\end{block}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   133
  \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   134
In []: a, b = 0, 1
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   135
In []: while b < 10:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   136
  ...:     print b,
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   137
  ...:     a, b = b, a + b
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   138
  ...:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   139
  ...:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   140
\end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   141
\typ{1 1 2 3 5 8}\\
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   142
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   143
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   144
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   145
\frametitle{\typ{range()}}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   146
\kwrd{range([start,] stop[, step])}\\
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   147
\begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   148
  \item \typ{range()} returns a list of integers
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   149
  \item The \typ{start} and the \typ{step} arguments are optional
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   150
  \item \typ{stop} is not included in the list
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   151
\end{itemize}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   152
\vspace*{.5in}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   153
\begin{block}{Documentation convention}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   154
  \begin{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   155
    \item \alert{Anything within \typ{[]} is optional}
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   156
    \item Nothing to do with Python.
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   157
  \end{itemize}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   158
\end{block}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   159
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   160
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   161
\begin{frame}[fragile]
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   162
  \frametitle{\texttt{for} \ldots \typ{range()}}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   163
Example: print squares of first \typ{5} numbers
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   164
  \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   165
In []: for i in range(5):
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   166
 ....:     print i, i * i
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   167
 ....:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   168
 ....:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   169
0 0
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   170
1 1
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   171
2 4
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   172
3 9
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   173
4 16
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   174
\end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   175
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   176
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   177
\begin{frame}[fragile]
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   178
  \frametitle{\texttt{for} \ldots \typ{range()}}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   179
Example: print squares of odd numbers from 3 to 9
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   180
  \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   181
In []: for i in range(3, 10, 2):
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   182
 ....:     print i, i * i
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   183
 ....:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   184
 ....:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   185
3 9
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   186
5 25
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   187
7 49
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   188
9 81
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   189
\end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   190
\inctime{5}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   191
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   192
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   193
\subsection{Exercises}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   194
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   195
\begin{frame}{Problem set 1: Problem 1.1}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   196
  Write a program that displays all three digit numbers that are equal to the sum of the cubes of their digits. That is, print numbers $abc$ that have the property $abc = a^3 + b^3 + c^3$\\
393
b7d2222b60a8 Added example for Amstrong numbers.
Puneeth Chaganti <punchagan@gmail.com>
parents: 389
diff changeset
   197
For example, $153 = 1^3 + 5^3 + 3^3$\\
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   198
\vspace*{0.2in}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   199
\emphbar{These are called $Armstrong$ numbers.}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   200
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   201
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   202
\begin{frame}{Problem 1.2 - Collatz sequence}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   203
\begin{enumerate}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   204
  \item Start with an arbitrary (positive) integer. 
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   205
  \item If the number is even, divide by 2; if the number is odd, multiply by 3 and add 1.
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   206
  \item Repeat the procedure with the new number.
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   207
  \item It appears that for all starting values there is a cycle of 4, 2, 1 at which the procedure loops.
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   208
\end{enumerate}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   209
    Write a program that accepts the starting value and prints out the Collatz sequence.
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   210
\inctime{5}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   211
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   212
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   213
\section{Data structures}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   214
\subsection{Lists}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   215
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   216
  \frametitle{Lists}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   217
\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
   218
  \begin{lstlisting}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   219
num = [1, 2, 3, 4]
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   220
  \end{lstlisting}
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   221
is a list
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   222
\end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   223
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   224
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   225
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   226
  \frametitle{Lists: methods}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   227
  \begin{lstlisting}
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   228
In []: num = [9, 8, 2, 3, 7]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   229
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   230
In []: num + [4, 5, 6]
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   231
Out[]: [9, 8, 2, 3, 7, 4, 5, 6]
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   232
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   233
In []: num.append([4, 5, 6])
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   234
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   235
In []: num
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   236
Out[]: [9, 8, 2, 3, 7, [4, 5, 6]]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   237
  \end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   238
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   239
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   240
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   241
  \frametitle{Lists: methods}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   242
  \begin{lstlisting}
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   243
In []: num = [9, 8, 2, 3, 7]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   244
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   245
In []: num.extend([4, 5, 6])
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   246
In []: num
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   247
Out[]: [9, 8, 2, 3, 7, 4, 5, 6]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   248
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   249
In []: num.reverse()
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   250
In []: num
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   251
Out[]: [6, 5, 4, 7, 3, 2, 8, 9]
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   252
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   253
In []: num.remove(6)
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   254
In []: num
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   255
  \end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   256
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   257
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   258
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   259
  \frametitle{Lists: slicing}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   260
  \begin{itemize}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   261
    \item \typ{list[initial:final]}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   262
  \end{itemize}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   263
\begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   264
In []: a = [1, 2, 3, 4, 5]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   265
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   266
In []: a[1:3]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   267
Out[]: [2, 3]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   268
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   269
In []: a[1:-1]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   270
Out[]: [2, 3, 4]
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   271
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   272
In []: a[:3]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   273
Out[]: [1, 2, 3]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   274
\end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   275
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   276
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   277
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   278
  \frametitle{Lists: slicing}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   279
  \begin{itemize}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   280
    \item \typ{list[initial:final:step]}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   281
  \end{itemize}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   282
\begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   283
In []: a[1:-1:2]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   284
Out[]: [2, 4]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   285
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   286
In []: a[::2]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   287
Out[]: [1, 3, 5]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   289
In []: a[-1::-1]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   290
Out[]: [5, 4, 3, 2, 1]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   291
\end{lstlisting}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   292
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   293
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   294
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   295
\frametitle{List containership}
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   296
\emphbar{Recall \typ{num} is \typ{[9, 8, 2, 3, 7]}}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   297
\begin{lstlisting}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   298
In []: 4 in num
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   299
Out[]: False
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   300
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   301
In []: b = 8
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   302
In []: b in num
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   303
Out[]: True
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   304
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   305
In []: b not in num
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   306
Out[]: False
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   307
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   308
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   309
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   310
\subsection{Tuples}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   311
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   312
\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
   313
\begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   314
In []: t = (1, 2, 3, 4, 5, 6, 7, 8)
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   315
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   316
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
   317
Out[]: 13
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   318
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   319
In []: t[4] = 7 
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   320
\end{lstlisting}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   321
\pause
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   322
\begin{block}{Note:}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   323
\begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   324
  \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
   325
\end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   326
\end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   327
  \inctime{10}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   328
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   329
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   330
\begin{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   331
  {A classic problem}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   332
  \begin{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   333
    {Interchange values}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   334
    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
   335
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   336
  \pause
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   337
  \begin{block}{Note:}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   338
    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
   339
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
   340
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   341
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   342
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   343
\subsection{Dictionaries}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   344
\begin{frame}[fragile]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   345
  \frametitle{Dictionaries: recall}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   346
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   347
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
   348
          '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
   349
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   350
In []: player['Avg']
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   351
Out[]: 52.530000000000001
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   352
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   353
  \begin{block}{Note!}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   354
    Duplicate keys $\Rightarrow$ overwritten!\\
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   355
    You can iterate through a dictionary using keys.
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   356
  \end{block}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   357
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   358
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   359
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   360
  \frametitle{Dictionaries: containership}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   361
  \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   362
In []: 'Inn' in player
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   363
Out[]: True
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   364
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   365
In []: 'Econ' in player
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   366
Out[]: False
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   367
  \end{lstlisting}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   368
  \begin{block}{Note}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   369
    \begin{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   370
      \item We can check for the containership of keys only
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   371
      \item Not values
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   372
    \end{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   373
  \end{block}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   374
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   375
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   376
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   377
  \frametitle{Dictionaries: methods}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   378
  \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   379
In []: player.keys()
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   380
Out[]: ['Runs', 'Inn', 'Avg', 'Mat']
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   381
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   382
In []: player.values()
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   383
Out[]: [10823, 233, 
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   384
        52.530000000000001, 134]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   385
  \end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   386
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   387
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   388
\begin{frame} {Problem Set 2.1: Problem 2.1.1}
380
669b72283b55 Updated after Day 2 at GRDCS
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 378
diff changeset
   389
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 program that takes such a string as input and prints a tuple (yyyy, mm, dd) where all three elements are ints.
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   390
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   391
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   392
\subsection{Sets}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   393
\begin{frame}[fragile]
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   394
  \frametitle{Sets}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   395
    \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   396
      \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
   397
      \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
   398
      \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
   399
      \item >, >=, <, <=, in, \ldots
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
    \begin{lstlisting}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   402
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   403
In []: f10 = set([1,2,3,5,8])
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   404
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   405
In []: p10 = set([2,3,5,7])
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   406
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   407
In []: f10 | p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   408
Out[]: set([1, 2, 3, 5, 7, 8])
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   409
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   410
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   411
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   412
\begin{frame}[fragile]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   413
  \frametitle{Set \ldots}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   414
    \begin{lstlisting}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   415
In []: f10 & p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   416
Out[]: set([2, 3, 5])
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   417
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   418
In []: f10 - p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   419
Out[]: set([1, 8])
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   420
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   421
In []: p10 - f10, f10 ^ p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   422
Out[]: (set([7]), set([1, 7, 8]))
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   423
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   424
In []: set([2,3]) < p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   425
Out[]: True
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   426
\end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   427
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   428
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   429
\begin{frame}[fragile]
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   430
  \frametitle{Set \ldots}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   431
    \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   432
In []: set([2,3]) <= p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   433
Out[]: True
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   434
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   435
In []: 2 in p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   436
Out[]: True
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   437
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   438
In []: 4 in p10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   439
Out[]: False
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   440
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   441
In []: len(f10)
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   442
Out[]: 5
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   443
\end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   444
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   445
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   446
\begin{frame}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   447
  \frametitle{Problem set 2.2: Problem 2.2.1}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   448
Given a dictionary of the names of students and their marks, identify how many duplicate marks are there? and what are these?
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   449
\end{frame}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   450
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   451
\begin{frame}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   452
  \frametitle{Problem 2.2.2}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   453
Given a list of words, find all the anagrams in the list.
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   454
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   455
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   456
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   457
\section{Functions}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   458
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   459
  \frametitle{Functions}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   460
  \begin{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   461
    \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
   462
    \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
   463
    \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
   464
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   465
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   466
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   467
\begin{frame}[fragile]
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   468
  \frametitle{Functions: example}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   469
  \begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   470
def signum( r ):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   471
    """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
   472
    -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
   473
    +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
   474
    if r < 0:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   475
        return -1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   476
    elif r > 0:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   477
        return 1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   478
    else:
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   479
        return 0
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   480
  \end{lstlisting}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   481
  \emphbar{Note docstrings}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   482
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   483
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   484
\begin{frame}[fragile]
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   485
  \frametitle {What does this function do?}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   486
  \begin{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   487
def what( n ):
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   488
    if n < 0: n = -n
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   489
    while n > 0:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   490
        if n % 2 == 1:
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   491
            return False
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   492
        n /= 10
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   493
    return True
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   494
  \end{lstlisting}
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   495
\end{frame} 
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   496
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   497
\begin{frame}[fragile]
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   498
  {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
   499
\begin{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   500
def what( n ):
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   501
    i = 1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   502
    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
   503
        i += 1
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   504
    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
   505
  \end{lstlisting}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   506
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   507
373
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   508
\begin{frame}[fragile]
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   509
  \frametitle {What does this function do?}
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   510
  \begin{lstlisting}
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   511
def what( x, n ):
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   512
    if n < 0: 
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   513
       n = -n
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   514
       x = 1.0 / x
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   515
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   516
    z = 1.0
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   517
    while n > 0:
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   518
        if n % 2 == 1:
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   519
            z *= x
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   520
        x *= x
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   521
        n /= 2
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   522
    return z
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   523
  \end{lstlisting}
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   524
\end{frame} 
f04eca8b2f3d Commits from NIT DGP and IITK
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 344
diff changeset
   525
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   526
\begin{frame}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   527
  \frametitle{What did we learn?}
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   528
  \begin{itemize}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   529
    \item Loops: \kwrd{while}, \kwrd{for}
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   530
    \item Advanced Data structures:
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   531
    \begin{itemize}
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   532
      \item Lists
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   533
      \item Tuples
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   534
      \item Dictionaries
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   535
      \item Sets
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   536
    \end{itemize}
288
c4e25269a86c Reorganized slides.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 251
diff changeset
   537
    \item Functions
297
a835affb1447 Added final changes to all day 2 slides for Calicut workshop.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 288
diff changeset
   538
    \item Docstrings
228
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   539
  \end{itemize}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   540
\end{frame}
238f3010c981 Created and made first cut slides for session 2 day 2.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
   541
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 297
diff changeset
   542
\end{document}
344
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   543
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   544
%% Questions for Quiz %%
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   545
%% ------------------ %%
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   546
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   547
\begin{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   548
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   549
  How do you find the presence of an element \emph{x} in the list \emph{a}?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   550
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   551
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   552
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   553
\begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   554
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   555
  \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   556
In []: set([1, 2, 8, 2, 13, 8, 9])
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   557
  \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   558
  What is the output?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   559
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   560
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   561
\begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   562
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   563
  \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   564
In []: a = {'a': 1, 'b': 2} 
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   565
In []: a['a'] = 10
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   566
In []: print a
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   567
  \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   568
  What is the output?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   569
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   570
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   571
\begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   572
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   573
  \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   574
In []: for i in range(3, 10, 2):
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   575
  ...:     print i
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   576
  \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   577
  What is the output?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   578
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   579
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   580
\begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   581
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   582
  \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   583
In []: a = [1, 2, 3] 
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   584
In []: a.extend([5, 6])
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   585
  \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   586
  What is the value of a?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   587
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   588
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   589
\begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   590
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   591
  \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   592
In []: a = (1, 2, 3)
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   593
In []: a[1] = 10
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   594
  \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   595
  What is the result?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   596
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   597
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   598
\begin{frame}[fragile]
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   599
    \frametitle{\incqno}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   600
  \begin{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   601
def func(x, y=10):
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   602
    print x+1, y+10
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   603
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   604
func(1)
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   605
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   606
  \end{lstlisting}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   607
  What is the output?
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   608
\end{frame}
19754ed6050f Moved all day2 quiz questions to end of day2-sessions.
Puneeth Chaganti <punchagan@fossee.in>
parents: 339
diff changeset
   609