|
1 % Created 2010-10-28 Thu 11:35 |
|
2 \documentclass[presentation]{beamer} |
|
3 \usepackage[latin1]{inputenc} |
|
4 \usepackage[T1]{fontenc} |
|
5 \usepackage{fixltx2e} |
|
6 \usepackage{graphicx} |
|
7 \usepackage{longtable} |
|
8 \usepackage{float} |
|
9 \usepackage{wrapfig} |
|
10 \usepackage{soul} |
|
11 \usepackage{t1enc} |
|
12 \usepackage{textcomp} |
|
13 \usepackage{marvosym} |
|
14 \usepackage{wasysym} |
|
15 \usepackage{latexsym} |
|
16 \usepackage{amssymb} |
|
17 \usepackage{hyperref} |
|
18 \tolerance=1000 |
|
19 \usepackage[english]{babel} \usepackage{ae,aecompl} |
|
20 \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
|
21 \usepackage{listings} |
|
22 \lstset{language=Python, basicstyle=\ttfamily\bfseries, |
|
23 commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
|
24 showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
|
25 \providecommand{\alert}[1]{\textbf{#1}} |
|
26 |
|
27 \title{Manipulating strings} |
|
28 \author{FOSSEE} |
|
29 \date{} |
|
30 |
|
31 \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} |
|
32 \begin{document} |
|
33 |
|
34 \maketitle |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 \begin{frame} |
|
45 \frametitle{Outline} |
|
46 \label{sec-1} |
|
47 |
|
48 \begin{itemize} |
|
49 \item Slicing strings to get sub-strings |
|
50 \item Reversing strings |
|
51 \item Replacing characters in strings. |
|
52 \item Converting strings to upper or lower case |
|
53 \item Joining a list of strings |
|
54 \end{itemize} |
|
55 \end{frame} |
|
56 \begin{frame} |
|
57 \frametitle{Question 1} |
|
58 \label{sec-2} |
|
59 |
|
60 Obtain the sub-string excluding the first and last characters from |
|
61 the string \texttt{s}. |
|
62 \end{frame} |
|
63 \begin{frame}[fragile] |
|
64 \frametitle{Solution 1} |
|
65 \label{sec-3} |
|
66 |
|
67 \begin{verbatim} |
|
68 In []: s[1:-1] |
|
69 \end{verbatim} |
|
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 \begin{verbatim} |
|
84 In []: s in week |
|
85 In []: s.lower()[:3] in week |
|
86 \end{verbatim} |
|
87 \end{frame} |
|
88 \begin{frame} |
|
89 \frametitle{Question 3} |
|
90 \label{sec-6} |
|
91 |
|
92 Given \texttt{email} -- \texttt{info@fossee[dot]in} |
|
93 |
|
94 Replace the \texttt{[dot]} with \texttt{.} in \texttt{email} |
|
95 \end{frame} |
|
96 \begin{frame}[fragile] |
|
97 \frametitle{Solution 3} |
|
98 \label{sec-7} |
|
99 |
|
100 \begin{verbatim} |
|
101 email.replace('[dot], '.') |
|
102 print email |
|
103 \end{verbatim} |
|
104 \end{frame} |
|
105 \begin{frame} |
|
106 \frametitle{Question 4} |
|
107 \label{sec-8} |
|
108 |
|
109 From the \texttt{email\_str} that we generated, change the separator to be a |
|
110 semicolon instead of a comma. |
|
111 \end{frame} |
|
112 \begin{frame}[fragile] |
|
113 \frametitle{Solution 4} |
|
114 \label{sec-9} |
|
115 |
|
116 \begin{verbatim} |
|
117 email_str = email_str.replace(",", ";") |
|
118 \end{verbatim} |
|
119 \end{frame} |
|
120 \begin{frame} |
|
121 \frametitle{Summary} |
|
122 \label{sec-10} |
|
123 |
|
124 You should now be able to -- |
|
125 \begin{itemize} |
|
126 \item Slice strings and get sub-strings out of them |
|
127 \item Reverse strings |
|
128 \item Replace characters in strings. |
|
129 \item Convert strings to upper or lower case |
|
130 \item Join a list of strings |
|
131 \end{itemize} |
|
132 \end{frame} |
|
133 \begin{frame} |
|
134 \frametitle{Thank you!} |
|
135 \label{sec-11} |
|
136 |
|
137 \begin{block}{} |
|
138 \begin{center} |
|
139 This spoken tutorial has been produced by the |
|
140 \textcolor{blue}{FOSSEE} team, which is funded by the |
|
141 \end{center} |
|
142 \begin{center} |
|
143 \textcolor{blue}{National Mission on Education through \\ |
|
144 Information \& Communication Technology \\ |
|
145 MHRD, Govt. of India}. |
|
146 \end{center} |
|
147 \end{block} |
|
148 \end{frame} |
|
149 |
|
150 \end{document} |