summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJovina2011-06-29 13:57:18 +0530
committerJovina2011-06-29 13:57:18 +0530
commit7b783e26304f54d7623570037cf85fee65ce06ee (patch)
treeebf0669e1a13cfaff91e60921548da825daca620
parent67effe3ddc032bee22bf34fa39ec1222255aca5a (diff)
downloadst-scripts-7b783e26304f54d7623570037cf85fee65ce06ee.tar.gz
st-scripts-7b783e26304f54d7623570037cf85fee65ce06ee.tar.bz2
st-scripts-7b783e26304f54d7623570037cf85fee65ce06ee.zip
Major changes to the script & slides of 'Manipulating lists'.
-rw-r--r--manipulating_lists/script.rst263
-rw-r--r--manipulating_lists/slides.org92
-rw-r--r--manipulating_lists/slides.tex144
3 files changed, 304 insertions, 195 deletions
diff --git a/manipulating_lists/script.rst b/manipulating_lists/script.rst
index 4b4bbf5..b8727a9 100644
--- a/manipulating_lists/script.rst
+++ b/manipulating_lists/script.rst
@@ -19,26 +19,32 @@
Script
------
-{{{ Show the slide containing the title }}}
+{{{ Show the first slide containing title, name of the production
+team along with the logo of MHRD }}}
-Hello friends. Welcome to this spoken tutorial on Manipulating Lists.
+Hello friends and Welcome to the tutorial on 'Manipulating Lists'.
-{{{ Show the slide containing the outline }}}
+{{{ Show the slide containing objectives }}}
-We have already learnt about Lists in Python. In this tutorial,
-we will learn about more advanced features of Lists in Python like how
-to concatenate two lists, details of slicing and striding of lists,
-methods to sort and reverse lists.
+At the end of this tutorial, you will be able to,
-{{{ Shift to terminal and start ipython }}}
+ 1. Concatenate two lists
+ #. Learn the details of slicing and striding of lists
+ #. Sort and reverse lists.
-To begin with let us start ipython, by typing::
+{{{ Switch to the pre-requisite slide }}}
- ipython
+Before beginning this tutorial,we would suggest you to complete the
+tutorial on "Getting started with Lists".
-on the terminal
+{{{ Open the terminal and start ipython }}}
-We already know what Lists are in Python, how to access individual
+let us start ipython on our terminal
+::
+
+ ipython
+
+We have already learnt about lists in Python, how to access individual
elements in the list and some of the functions that can be run on the
lists like ``max, min, sum, len`` and so on. Now let us learn some of
the basic operations that can be performed on Lists.
@@ -46,193 +52,240 @@ the basic operations that can be performed on Lists.
We already know how to access individual elements in a List. But what
if we have a scenario where we need to get a part of the entire list
or what we call as a slice of the list? Python supports slicing on
-lists. Let us say I have the list::
+lists. Let us say I have the list,
+::
- primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
+ primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
To obtain all the primes between 10 and 20 from the above list of
-primes we say::
+primes we say
+::
- primes[4:8]
+ primes[4:8]
This gives us all the elements in the list starting from the element
-with the index 4, which is 11 in our list, upto the element with index 8
-in the list but not including the eigth element. So we obtain a slice
-starting from 11 upto 19th. It is a very important to remember that
-whenever we specify a range of elements in Python the start index is
-included and end index is not included. So in the above case, 11 which
-was the element with the index 4 was included but 23 which was the
+with the index 4, which is 11, upto the element with index 8
+in the list but not including the eighth element. So we obtain a slice
+starting from 11 upto 19th. It is very important to remember that
+whenever we specify a range of elements in Python, the start index is
+included and end index is not included. So in the above case, 11, which
+was the element with the index 4, was included but 23 which was the
element with index 8 was excluded.
-Following is an exercise you must do.
+Pause the video here, try out the following exercise and resume the video.
-%% %% Obtain the primes less than 10, from the list ``primes``.
+{{{ Show slide with exercise 1 }}}
-Please, pause the video here, do the exercise and then resume.
+ Obtain the primes less than 10, from the list ``primes``.
+Switch to the terminal for solution
+
+{{{continue from paused state}}}
+{{{ Switch to the terminal }}}
::
- primes[0:4]
+ primes[0:4]
+
+It give us the primes below 10.
-will give us the primes below 10.
+{{{ Show the slide containing p[start:stop] }}}
Generalizing, we can obtain a slice of the list "p" from the index
-"start" upto the index "end" but excluding "end" with the following
-syntax
+"start" upto the index "end" but excluding "end" with the
+syntax ``p[start:stop]``
-{{{ Show the slide containing p[start:stop] }}}
+{{{ Switch to terminal }}}
By default the slice fetches all the elements between start and stop
including start but not stop. So as to say we obtain all the elements
between start and stop in steps of one. Python also provides us the
functionality to specify the steps in which the slice must be
-obtained. Say we have::
+obtained. Say we have
+::
- num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
+ num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
If we want to obtain all the odd numbers less than 10 from the list
``num`` we have to start from element with index 1 upto the index 10 in
-steps of 2::
+steps of 2
+::
- num[1:10:2]
+ num[1:10:2]
When no step is specified, it is assumed to be 1. Similarly, there are
default values for start and stop indices as well. If we don't specify
-the start index it is implicitly taken as the first element of the
-list::
+the start index, it is implicitly taken as the first element of the
+list
+::
- num[:10]
+ num[:10]
This gives us all the elements from the beginning upto the 10th
-element but not including the 10th element in the list "num". Similary
-if the stop index is not specified it is implicitly assumed to be the
-end of the list, including the last element of the list::
+element but not including the 10th element in the list. Similarly
+if the stop index is not specified, it is implicitly assumed to be the
+end of the list, including the last element of the list
+::
- num[10:]
+ num[10:]
-gives all the elements starting from the 10th element in the list
-"num" upto the final element including that last element. Now::
+This gives all the elements starting from the 10th element in the list
+"num" upto the final element including that last element.
- num[::2]
-gives us all the even numbers in the list "num".
+To get all the even numbers in the list "num", we do
+::
-Following is an exercise that you must do.
+ num[::2]
-%% %% Obtain all the multiples of three from the list ``num``.
+Pause the video here, try out the following exercise and resume the video.
-Please, pause the video here. Do the exercise and then continue.
+{{{ Show slide with exercise 2 }}}
-::
+ Obtain all the multiples of three from the list ``num``.
- num[::3]
+{{{ Show slide with Solution 2 }}}
-gives us all the multiples of 3 from the list, since every third
-element in it, starting from 0, is divisible by 3.
+ ``num[::3]`` gives us all the multiples of 3 from the list, since every
+third element in it, starting from 0, is divisible by 3.
The other basic operation that we can perform on lists is concatenation
of two or more lists. We can combine two lists by using the "plus"
operator. Say we have
-{{{ Read as you type }}}::
+::
- a = [1, 2, 3, 4]
- b = [4, 5, 6, 7]
- a + b
+ a = [1, 2, 3, 4]
+ b = [4, 5, 6, 7]
+ a + b
When we concatenate lists using the "plus" operator we get a new
-list. We can store this list in a new variable::
+list. We can store this list in a new variable,say c,
+::
- c = a + b
- c
+ c = a + b
+ c
It is important to observe that the "plus" operator always returns a
new list without altering the lists being concatenated in any way.
We know that a list is a collection of data. Whenever we have a
-collection we run into situations where we want to sort the
-collection. Lists support sort method which sorts the list inplace::
+collection, we run into situations where we want to sort the
+collection. Lists support ``sort`` method which sorts the list in place
+::
- a = [5, 1, 6, 7, 7, 10]
- a.sort()
+ a = [5, 1, 6, 7, 7, 10]
+ a.sort()
-Now the contents of the list ``a`` will be::
+Now the contents of the list ``a`` will be
+::
- a
- [1, 5, 6, 7, 7, 10]
+ a
-As the sort method sorts the elements of a list, the original list we had
-is overwritten or replaced. We have no way to obtain the original list
-back. One way to avoid this is to keep a copy of the original list in
-another variable and run the sort method on the list. However Python
-also provides a built-in function called sorted which sorts the list
-which is passed as an argument to it and returns a new sorted list::
+As the ``sort`` method sorts the elements of a list, the original list
+we had, is overwritten or replaced. We have no way to obtain the
+original list back. One way to avoid this is to keep a copy of the
+original list in another variable and run the sort method on the list.
+However Python also provides a built-in function called sorted which
+sorts the list which is passed as an argument to it and returns a new
+sorted list
+::
- a = [5, 1, 6, 7, 7, 10]
- sorted(a)
+ a = [5, 1, 6, 7, 7, 10]
+ sorted(a)
-We can store this sorted list another list variable::
+We can store this sorted list into another list variable
+::
- sa = sorted(a)
+ sa = sorted(a)
-Python also provides the reverse method which reverses
-the list inplace::
+Python also provides the ``reverse`` method which reverses
+the list in place
+::
- a = [1, 2, 3, 4, 5]
- a.reverse()
+ a = [1, 2, 3, 4, 5]
+ a.reverse()
-reverses the list "a" and stores the reversed list inplace i.e. in "a"
-itself. Lets see the list "a"::
+the ``reverse`` method reverses the list "a" and stores the reversed
+list in place i.e. in "a" itself. Lets see the list "a"
+::
- a
- [5, 4, 3, 2, 1]
+ a
But again the original list is lost.
-.. #[punch: removed reversed, since it returns an iterator]
-To reverse a list, we could use striding with negative indexing.::
+To reverse a list, we could use striding with negative indexing.
+::
- a[::-1]
+ a[::-1]
We can also store this new reversed list in another list variable.
-Following is an (are) exercise(s) that you must do.
+ Pause the video here, try out the following exercise and resume the video.
-%% %% Given a list of marks of students in an examination, obtain a
- list with marks in descending order.
- ::
+{{{ Show slide with exercise 3 }}}
- marks = [99, 67, 47, 100, 50, 75, 62]
+ Given a list of marks of students in an examination, obtain a
+ list with marks in descending order.
+ marks = [99, 67, 47, 100, 50, 75, 62]
-Please, pause the video here. Do the exercise(s) and then continue.
+Switch to terminal for solution.
+{{{continue from paused state}}}
+{{{ Switch to the terminal }}}
::
- sorted(marks)[::-1]
+ sorted(marks)[::-1]
OR
::
+
+ sorted(marks, reverse = True)
- sorted(marks, reverse = True)
+{{{ Show summary slide }}}
+This brings us to the end of this tutorial. In this tutorial,
+we have learnt to,
+ 1. Obtain parts of lists using slicing and striding.
+ #. Concatenate lists using the ``plus`` operator.
+ #. Sort lists using the ``sort`` method.
+ #. Use the method ``reverse`` to reverse the lists.
+
+{{{Show self assessment questions slide}}}
+
+Here are some self assessment questions for you to solve
+
+1. Given the list primes, ``primes = [2, 3, 5, 7, 11, 13, 17, 19, 23,
+ 29]``, How do you obtain the last 4 primes?
-{{{ Show summary slide }}}
-This brings us to the end of another session. In this tutorial session
-we learnt
+2. Given a list, p, of unknown length, obtain the first 3 (or all, if
+ there are fewer) characters of it.
+
+
+3. ``reversed`` function reverses a list in place. True or False?
+
+
+{{{solution of self assessment questions on slide}}}
+
+And the answers,
+
+1. The last four primes can be obtained from the given list as,
+::
+
+ primes[-4:]
+
+2. The first 3 characters can be obtained as,
+::
- * Obtaining parts of lists using slicing and striding
- * List concatenation
- * Sorting lists
- * Reversing lists
+ p[:3]
-{{{ Show the "sponsored by FOSSEE" slide }}}
+3. False. The function ``reverse`` will reverse a list in place.
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+{{{ Show the thank you slide }}}
-Hope you have enjoyed and found it useful.
+Hope you have enjoyed this tutorial and found it useful.
Thank you!
diff --git a/manipulating_lists/slides.org b/manipulating_lists/slides.org
index c0eea62..090e96d 100644
--- a/manipulating_lists/slides.org
+++ b/manipulating_lists/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Manipulating Lists
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -30,63 +30,85 @@
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
-* Outline
- In this session we shall be looking at
- - Concatenating lists
- - Obtaining parts of lists
- - Sorting lists
- - Reversing lists
-* Question 1
- Obtain the primes less than 10, from the list ~primes~.
-* Solution 1
- #+begin_src python
- primes[0:4]
- #+end_src python
+*
+#+begin_latex
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Manipulating Lists}
+\end{center}
+\vspace{18pt}
+\begin{center}
+\vspace{10pt}
+\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
+\vspace{5pt}
+\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\
+\scriptsize Funded by National Mission on Education through ICT\\
+\scriptsize MHRD,Govt. of India\\
+\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
+\end{center}
+#+end_latex
+* Objectives
+ At the end of this tutorial, you will be able to,
+
+ - Concatenate two lists.
+ - Learn the details of slicing and striding of lists.
+ - Sort and reverse lists.
+* Pre-requisite
+Spoken tutorial on -
+- Getting started with Lists.
+* Exercise 1
+ Obtain the primes less than 10, from the list ~primes~.
* Slicing
#+begin_src python
p[start:stop]
#+end_src python
- Returns all elements of ~p~ between ~start~ and ~stop~
- The element with index equal to ~stop~ is *not* included.
-* Question 2
+* Exercise 2
Obtain all the multiples of three from the list ~num~.
* Solution 2
#+begin_src python
num[::3]
#+end_src python
-* Question 3
+* Exercise 3
Given a list of marks of students in an examination, obtain a list
with marks in descending order.
#+begin_src python
marks = [99, 67, 47, 100, 50, 75, 62]
#+end_src python
-* Solution 3
- #+begin_src python
- sorted(marks)[::-1]
- #+end_src python
-OR
- #+begin_src python
- sorted(marks, reverse=True)
- #+end_src python
-
* Summary
- In this tutorial session we learnt
- + Obtaining parts of lists using slicing and striding
- + List concatenation
- + Sorting lists
- + Reversing lists
+ In this tutorial, we have learnt to,
+
+ - Obtain parts of lists using slicing and striding.
+ - Concatenate lists using the ``plus'' operator.
+ - Sort lists using the ``sort'' method.
+ - Use the method ``reverse'' to reverse the lists.
+
+* Evaluation
+1. Given the list primes, primes = [2, 3, 5, 7, 11, 13, 17, 19, 23,
+ 29], How do you obtain the last 4 primes?
-* Thank you!
+2. Given a list, p, of unknown length, obtain the first 3 (or all, if
+ there are fewer) characters of it.
+
+3. ``reversed'' function reverses a list in place. True or False?
+* Solutions
+1. primes[-4:]
+
+2. p[:3]
+
+3. False
+*
#+begin_latex
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
#+end_latex
diff --git a/manipulating_lists/slides.tex b/manipulating_lists/slides.tex
index 5b02407..cf085fb 100644
--- a/manipulating_lists/slides.tex
+++ b/manipulating_lists/slides.tex
@@ -1,4 +1,4 @@
-% Created 2010-11-09 Tue 16:07
+% Created 2011-06-29 Wed 13:50
\documentclass[presentation]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
@@ -23,14 +23,14 @@ commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\providecommand{\alert}[1]{\textbf{#1}}
-\title{Manipulating Lists}
+\title{}
\author{FOSSEE}
\date{}
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}
-\maketitle
+
@@ -41,54 +41,74 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
- In this session we shall be looking at
-\begin{itemize}
-\item Concatenating lists
-\item Obtaining parts of lists
-\item Sorting lists
-\item Reversing lists
-\end{itemize}
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Manipulating Lists}
+\end{center}
+\vspace{18pt}
+\begin{center}
+\vspace{10pt}
+\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
+\vspace{5pt}
+\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\
+\scriptsize Funded by National Mission on Education through ICT\\
+\scriptsize MHRD,Govt. of India\\
+\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
+\end{center}
\end{frame}
\begin{frame}
-\frametitle{Question 1}
+\frametitle{Objectives}
\label{sec-2}
- Obtain the primes less than 10, from the list \texttt{primes}.
+ At the end of this tutorial, you will be able to,
+
+
+\begin{itemize}
+\item Concatenate two lists.
+\item Learn the details of slicing and striding of lists.
+\item Sort and reverse lists.
+\end{itemize}
\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
+\begin{frame}
+\frametitle{Pre-requisite}
\label{sec-3}
-\lstset{language=Python}
-\begin{lstlisting}
-primes[0:4]
-\end{lstlisting}
+Spoken tutorial on -
+
+\begin{itemize}
+\item Getting started with Lists.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Exercise 1}
+\label{sec-4}
+
+ Obtain the primes less than 10, from the list \verb~primes~.
\end{frame}
\begin{frame}[fragile]
\frametitle{Slicing}
-\label{sec-4}
+\label{sec-5}
\lstset{language=Python}
\begin{lstlisting}
p[start:stop]
\end{lstlisting}
+
\begin{itemize}
-\item Returns all elements of \texttt{p} between \texttt{start} and \texttt{stop}
-\item The element with index equal to \texttt{stop} is \textbf{not} included.
+\item Returns all elements of \verb~p~ between \verb~start~ and \verb~stop~
+\item The element with index equal to \verb~stop~ is \textbf{not} included.
\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Question 2}
-\label{sec-5}
+\frametitle{Exercise 2}
+\label{sec-6}
- Obtain all the multiples of three from the list \texttt{num}.
+ Obtain all the multiples of three from the list \verb~num~.
\end{frame}
\begin{frame}[fragile]
\frametitle{Solution 2}
-\label{sec-6}
+\label{sec-7}
\lstset{language=Python}
\begin{lstlisting}
@@ -96,8 +116,8 @@ num[::3]
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
-\frametitle{Question 3}
-\label{sec-7}
+\frametitle{Exercise 3}
+\label{sec-8}
Given a list of marks of students in an examination, obtain a list
with marks in descending order.
@@ -106,47 +126,61 @@ num[::3]
marks = [99, 67, 47, 100, 50, 75, 62]
\end{lstlisting}
\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 3}
-\label{sec-8}
-
-\lstset{language=Python}
-\begin{lstlisting}
-sorted(marks)[::-1]
-\end{lstlisting}
-OR
-\lstset{language=Python}
-\begin{lstlisting}
-sorted(marks, reverse=True)
-\end{lstlisting}
-\end{frame}
\begin{frame}
\frametitle{Summary}
\label{sec-9}
- In this tutorial session we learnt
+ In this tutorial, we have learnt to,
+
+
\begin{itemize}
-\item Obtaining parts of lists using slicing and striding
-\item List concatenation
-\item Sorting lists
-\item Reversing lists
+\item Obtain parts of lists using slicing and striding.
+\item Concatenate lists using the ``plus'' operator.
+\item Sort lists using the ``sort'' method.
+\item Use the method ``reverse'' to reverse the lists.
\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Thank you!}
+\frametitle{Evaluation}
\label{sec-10}
+
+\begin{enumerate}
+\item Given the list primes,\\ primes = [2, 3, 5, 7, 11, 13, 17, 19, 23,
+ 29],\\ How do you obtain the last 4 primes?
+\vspace{11pt}
+\item Given a list, p, of unknown length, obtain the first 3 (or all, if
+ there are fewer) characters of it.
+\vspace{11pt}
+\item ``reversed'' function reverses a list in place. True or False?
+\end{enumerate}
+\end{frame}
+\begin{frame}
+\frametitle{Solutions}
+\label{sec-11}
+
+
+\begin{enumerate}
+\item primes[-4:]
+\vspace{8pt}
+\item p[:3]
+\vspace{8pt}
+\item False
+\end{enumerate}
+\end{frame}
+\begin{frame}
+
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
\end{frame}
-\end{document}
+\end{document} \ No newline at end of file