summaryrefslogtreecommitdiff
path: root/manipulating-strings/script.rst
diff options
context:
space:
mode:
authorPuneeth Chaganti2010-10-08 16:11:20 +0530
committerPuneeth Chaganti2010-10-08 16:11:20 +0530
commit0f24b97fba8b5b1a11d9e94ddc03e5183ae4e19f (patch)
tree11997757cba5e2cc769815bd846480e287d6da73 /manipulating-strings/script.rst
parent628413c1b9694a5d173f6c35742fb54d0ea4f1e1 (diff)
downloadst-scripts-0f24b97fba8b5b1a11d9e94ddc03e5183ae4e19f.tar.gz
st-scripts-0f24b97fba8b5b1a11d9e94ddc03e5183ae4e19f.tar.bz2
st-scripts-0f24b97fba8b5b1a11d9e94ddc03e5183ae4e19f.zip
Added questions to manipulating strings LO.
Diffstat (limited to 'manipulating-strings/script.rst')
-rw-r--r--manipulating-strings/script.rst39
1 files changed, 35 insertions, 4 deletions
diff --git a/manipulating-strings/script.rst b/manipulating-strings/script.rst
index 4b28b55..1ba16d1 100644
--- a/manipulating-strings/script.rst
+++ b/manipulating-strings/script.rst
@@ -7,13 +7,14 @@
.. #. Reverse strings
.. #. Replace characters in strings.
.. #. Convert to strings to upper or lower case
+.. #. joining a list of strings
.. Prerequisites
.. -------------
.. 1. getting started with strings
.. #. getting started with lists
-.. #.
+.. #. basic datatypes
.. Author : Puneeth
Internal Reviewer :
@@ -31,9 +32,9 @@ Hello Friends. Welcome to this tutorial on manipulating strings.
In this tutorial we shall learn to manipulate strings, specifically
slicing and reversing them, or replacing characters, converting from
-upper to lower case and vice-versa
+upper to lower case and vice-versa and joining a list of strings.
-#[punch: reversed returns an iterator. should we still teach it?]
+.. #[punch: reversed returns an iterator. should we still teach it?]
We have an ``ipython`` shell open, in which we are going to work,
through out this session.
@@ -199,13 +200,43 @@ Please, pause the video here. Do the exercise and then continue.
email = email.replace("[dot]", ".")
print email
+Now, let's look at another interesting problem where we have a list of
+e-mail addresses and we wish to obtain one long string of e-mail
+addresses separated by commas or semi-colons.
+
+::
+
+ email_list = ["info@fossee.in", "enquiries@fossee.in", "help@fossee.in"]
+
+
+Now, if we wish to obtain one long string, separating each of the
+email id by a comma, we use the join operator on ``,``.
+
+::
+
+ email_str = ", ".join(email_list)
+ print email_str
+
+Notice that the email ids are joined by a comma followed by a space.
+
+Following is an exercise that you must do.
+
+%%3%% From the email_str that we generated, change the separator to be
+a semicolon instead of a comma.
+
+Please, pause the video here. Do the exercise and then continue.
+
+::
+
+ email_str = email_str.replace(",", ";")
That brings us to the end of the tutorial.
{{{ show summary slide }}}
In this tutorial, we have learnt how to get substrings, reverse
-strings and a few useful methods, namely upper, lower and replace.
+strings and a few useful methods, namely upper, lower, replace and
+join.
{{{ Show the "sponsored by FOSSEE" slide }}}