manipulating-strings/slides.tex
changeset 286 44f06ae0d957
parent 217 b595f90016c5
child 367 2ca9b21ed8f9
equal deleted inserted replaced
285:7c4855fb8e5f 286:44f06ae0d957
     1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1 % Created 2010-10-11 Mon 11:27
     2 %Tutorial slides on Python.
     2 \documentclass[presentation]{beamer}
     3 %
     3 \usepackage[latin1]{inputenc}
     4 % Author: FOSSEE 
     4 \usepackage[T1]{fontenc}
     5 % Copyright (c) 2009, FOSSEE, IIT Bombay
     5 \usepackage{fixltx2e}
     6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     6 \usepackage{graphicx}
       
     7 \usepackage{longtable}
       
     8 \usepackage{float}
       
     9 \usepackage{wrapfig}
       
    10 \usepackage{soul}
       
    11 \usepackage{textcomp}
       
    12 \usepackage{marvosym}
       
    13 \usepackage{wasysym}
       
    14 \usepackage{latexsym}
       
    15 \usepackage{amssymb}
       
    16 \usepackage{hyperref}
       
    17 \tolerance=1000
       
    18 \usepackage[english]{babel} \usepackage{ae,aecompl}
       
    19 \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
       
    20 \usepackage{listings}
       
    21 \lstset{language=Python, basicstyle=\ttfamily\bfseries,
       
    22 commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
       
    23 showstringspaces=false, keywordstyle=\color{blue}\bfseries}
       
    24 \providecommand{\alert}[1]{\textbf{#1}}
     7 
    25 
     8 \documentclass[14pt,compress]{beamer}
    26 \title{Manipulating strings}
     9 %\documentclass[draft]{beamer}
    27 \author{FOSSEE}
    10 %\documentclass[compress,handout]{beamer}
       
    11 %\usepackage{pgfpages} 
       
    12 %\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
       
    13 
       
    14 % Modified from: generic-ornate-15min-45min.de.tex
       
    15 \mode<presentation>
       
    16 {
       
    17   \usetheme{Warsaw}
       
    18   \useoutertheme{infolines}
       
    19   \setbeamercovered{transparent}
       
    20 }
       
    21 
       
    22 \usepackage[english]{babel}
       
    23 \usepackage[latin1]{inputenc}
       
    24 %\usepackage{times}
       
    25 \usepackage[T1]{fontenc}
       
    26 
       
    27 \usepackage{ae,aecompl}
       
    28 \usepackage{mathpazo,courier,euler}
       
    29 \usepackage[scaled=.95]{helvet}
       
    30 
       
    31 \definecolor{darkgreen}{rgb}{0,0.5,0}
       
    32 
       
    33 \usepackage{listings}
       
    34 \lstset{language=Python,
       
    35     basicstyle=\ttfamily\bfseries,
       
    36     commentstyle=\color{red}\itshape,
       
    37   stringstyle=\color{darkgreen},
       
    38   showstringspaces=false,
       
    39   keywordstyle=\color{blue}\bfseries}
       
    40 
       
    41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    42 % Macros
       
    43 \setbeamercolor{emphbar}{bg=blue!20, fg=black}
       
    44 \newcommand{\emphbar}[1]
       
    45 {\begin{beamercolorbox}[rounded=true]{emphbar} 
       
    46       {#1}
       
    47  \end{beamercolorbox}
       
    48 }
       
    49 \newcounter{time}
       
    50 \setcounter{time}{0}
       
    51 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
       
    52 
       
    53 \newcommand{\typ}[1]{\lstinline{#1}}
       
    54 
       
    55 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
       
    56 
       
    57 % Title page
       
    58 \title{Your Title Here}
       
    59 
       
    60 \author[FOSSEE] {FOSSEE}
       
    61 
       
    62 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
       
    63 \date{}
    28 \date{}
    64 
    29 
    65 % DOCUMENT STARTS
    30 \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
    66 \begin{document}
    31 \begin{document}
    67 
    32 
    68 \begin{frame}
    33 \maketitle
    69   \maketitle
       
    70 \end{frame}
       
    71 
    34 
    72 \begin{frame}[fragile]
       
    73   \frametitle{Outline}
       
    74   \begin{itemize}
       
    75     \item 
       
    76   \end{itemize}
       
    77 \end{frame}
       
    78 
    35 
    79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    80 %%              All other slides here.                  %%
       
    81 %% The same slides will be used in a classroom setting. %% 
       
    82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    83 
    36 
    84 \begin{frame}[fragile]
    37 
    85   \frametitle{Summary}
    38 
    86   \begin{itemize}
    39 
    87     \item 
    40 
    88   \end{itemize}
    41 
    89 \end{frame}
       
    90 
    42 
    91 \begin{frame}
    43 \begin{frame}
    92   \frametitle{Thank you!}  
    44 \frametitle{Outline}
       
    45 \label{sec-1}
       
    46 
       
    47 \begin{itemize}
       
    48 \item Slicing strings to get sub-strings
       
    49 \item Reversing strings
       
    50 \item Replacing characters in strings.
       
    51 \item Converting strings to upper or lower case
       
    52 \item Joining a list of strings
       
    53 \end{itemize}
       
    54 \end{frame}
       
    55 \begin{frame}
       
    56 \frametitle{Question 1}
       
    57 \label{sec-2}
       
    58 
       
    59   Obtain the sub-string excluding the first and last characters from
       
    60   the string \texttt{s}.
       
    61 \end{frame}
       
    62 \begin{frame}[fragile]
       
    63 \frametitle{Solution 1}
       
    64 \label{sec-3}
       
    65 
       
    66 \lstset{language=Python}
       
    67 \begin{lstlisting}
       
    68 In []:  s[1:-1]
       
    69 \end{lstlisting}
       
    70 \end{frame}
       
    71 \begin{frame}
       
    72 \frametitle{Question 2}
       
    73 \label{sec-4}
       
    74 
       
    75   Given a list week, week = \texttt{week = ["sun", "mon", "tue", "wed",   "thu", "fri", "sat"]}. Check if \texttt{s} is a valid name of a day of the
       
    76   week. Change the solution to this problem, to include forms like,
       
    77   SAT, SATURDAY, Saturday and Sat.
       
    78 \end{frame}
       
    79 \begin{frame}[fragile]
       
    80 \frametitle{Solution 2}
       
    81 \label{sec-5}
       
    82 
       
    83 \lstset{language=Python}
       
    84 \begin{lstlisting}
       
    85 In []:  s in week
       
    86 In []:  s.lower()[:3] in week
       
    87 \end{lstlisting}
       
    88 \end{frame}
       
    89 \begin{frame}
       
    90 \frametitle{Question 3}
       
    91 \label{sec-6}
       
    92 
       
    93   Given \texttt{email} -- \texttt{info@fossee[dot]in}
       
    94 
       
    95   Replace the \texttt{[dot]} with \texttt{.} in \texttt{email}
       
    96 \end{frame}
       
    97 \begin{frame}[fragile]
       
    98 \frametitle{Solution 3}
       
    99 \label{sec-7}
       
   100 
       
   101 \lstset{language=Python}
       
   102 \begin{lstlisting}
       
   103 email.replace('[dot], '.')
       
   104 print email
       
   105 \end{lstlisting}
       
   106 \end{frame}
       
   107 \begin{frame}
       
   108 \frametitle{Question 4}
       
   109 \label{sec-8}
       
   110 
       
   111   From the \texttt{email\_str} that we generated, change the separator to be a
       
   112   semicolon instead of a comma.
       
   113 \end{frame}
       
   114 \begin{frame}[fragile]
       
   115 \frametitle{Solution 4}
       
   116 \label{sec-9}
       
   117 
       
   118 \lstset{language=Python}
       
   119 \begin{lstlisting}
       
   120 email_str = email_str.replace(",", ";")
       
   121 \end{lstlisting}
       
   122 \end{frame}
       
   123 \begin{frame}
       
   124 \frametitle{Summary}
       
   125 \label{sec-10}
       
   126 
       
   127   You should now be able to --
       
   128 \begin{itemize}
       
   129 \item Slice strings and get sub-strings out of them
       
   130 \item Reverse strings
       
   131 \item Replace characters in strings.
       
   132 \item Convert strings to upper or lower case
       
   133 \item Join a list of strings
       
   134 \end{itemize}
       
   135 \end{frame}
       
   136 \begin{frame}
       
   137 \frametitle{Thank you!}
       
   138 \label{sec-11}
       
   139 
    93   \begin{block}{}
   140   \begin{block}{}
    94   \begin{center}
   141   \begin{center}
    95   This spoken tutorial has been produced by the
   142   This spoken tutorial has been produced by the
    96   \textcolor{blue}{FOSSEE} team, which is funded by the 
   143   \textcolor{blue}{FOSSEE} team, which is funded by the 
    97   \end{center}
   144   \end{center}