author | Puneeth Chaganti <punchagan@gmail.com> |
Tue, 26 Oct 2010 14:50:33 +0530 | |
changeset 354 | 4c09238600e0 |
parent 286 | 44f06ae0d957 |
permissions | -rw-r--r-- |
286
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
1 |
#+LaTeX_CLASS: beamer |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
2 |
#+LaTeX_CLASS_OPTIONS: [presentation] |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
3 |
#+BEAMER_FRAME_LEVEL: 1 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
4 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
5 |
#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
6 |
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
7 |
#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
8 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
9 |
#+LaTeX_CLASS: beamer |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
10 |
#+LaTeX_CLASS_OPTIONS: [presentation] |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
11 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
12 |
#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
13 |
#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
14 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
15 |
#+LaTeX_HEADER: \usepackage{listings} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
16 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
17 |
#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
18 |
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
19 |
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
20 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
21 |
#+TITLE: Manipulating strings |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
22 |
#+AUTHOR: FOSSEE |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
23 |
#+EMAIL: |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
24 |
#+DATE: |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
25 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
26 |
#+DESCRIPTION: |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
27 |
#+KEYWORDS: |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
28 |
#+LANGUAGE: en |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
29 |
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
30 |
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
31 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
* Outline |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
33 |
- Slicing strings to get sub-strings |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
34 |
- Reversing strings |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
35 |
- Replacing characters in strings. |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
36 |
- Converting strings to upper or lower case |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
37 |
- Joining a list of strings |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
38 |
* Question 1 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
39 |
Obtain the sub-string excluding the first and last characters from |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
40 |
the string ~s~. |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
* Solution 1 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
#+begin_src python |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
43 |
In []: s[1:-1] |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
44 |
#+end_src |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
45 |
* Question 2 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
46 |
Given a list week, week = ~week = ["sun", "mon", "tue", "wed", |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
47 |
"thu", "fri", "sat"]~. Check if ~s~ is a valid name of a day of the |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
48 |
week. Change the solution to this problem, to include forms like, |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
49 |
SAT, SATURDAY, Saturday and Sat. |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
50 |
* Solution 2 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
51 |
#+begin_src python |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
52 |
In []: s in week |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
53 |
In []: s.lower()[:3] in week |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
54 |
#+end_src |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
55 |
* Question 3 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
56 |
Given ~email~ -- ~info@fossee[dot]in~ |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
57 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
58 |
Replace the ~[dot]~ with ~.~ in ~email~ |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
59 |
* Solution 3 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
60 |
#+begin_src python |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
61 |
email.replace('[dot], '.') |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
62 |
print email |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
63 |
#+end_src |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
64 |
* Question 4 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
65 |
From the ~email_str~ that we generated, change the separator to be a |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
66 |
semicolon instead of a comma. |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
67 |
* Solution 4 |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
68 |
#+begin_src python |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
69 |
email_str = email_str.replace(",", ";") |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
70 |
#+end_src |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
71 |
* Summary |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
72 |
You should now be able to -- |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
73 |
- Slice strings and get sub-strings out of them |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
74 |
- Reverse strings |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
75 |
- Replace characters in strings. |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
76 |
- Convert strings to upper or lower case |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
77 |
- Join a list of strings |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
78 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
79 |
* Thank you! |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
80 |
#+begin_latex |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
81 |
\begin{block}{} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
82 |
\begin{center} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
83 |
This spoken tutorial has been produced by the |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
84 |
\textcolor{blue}{FOSSEE} team, which is funded by the |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
85 |
\end{center} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
86 |
\begin{center} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
87 |
\textcolor{blue}{National Mission on Education through \\ |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
88 |
Information \& Communication Technology \\ |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
89 |
MHRD, Govt. of India}. |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
90 |
\end{center} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
91 |
\end{block} |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
92 |
#+end_latex |
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
93 |
|
44f06ae0d957
Slides for manipulating strings LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
94 |