summaryrefslogtreecommitdiff
path: root/sets
diff options
context:
space:
mode:
authorJovina2011-07-07 12:04:28 +0530
committerJovina2011-07-07 12:04:28 +0530
commite4f4729e02d3a550f74c52210ea619f8dadb4283 (patch)
tree823c2b5509cfbba45c959e171061ee11e72e0d48 /sets
parentab0b9d6fa8b1971433d1daf092afeb83aae2256c (diff)
downloadst-scripts-e4f4729e02d3a550f74c52210ea619f8dadb4283.tar.gz
st-scripts-e4f4729e02d3a550f74c52210ea619f8dadb4283.tar.bz2
st-scripts-e4f4729e02d3a550f74c52210ea619f8dadb4283.zip
Major changes to script & slides of 'Sets'.
Diffstat (limited to 'sets')
-rw-r--r--sets/script.rst244
-rw-r--r--sets/slides.org97
-rw-r--r--sets/slides.tex132
3 files changed, 362 insertions, 111 deletions
diff --git a/sets/script.rst b/sets/script.rst
index a2e851a..664318c 100644
--- a/sets/script.rst
+++ b/sets/script.rst
@@ -23,121 +23,219 @@
Script
------
-{{{ Show the slide containing title }}}
+.. L1
-Hello friends and welcome to the tutorial on Sets
+{{{ Show the first slide containing title, name of the production
+team along with the logo of MHRD }}}
-{{{ Show the slide containing the outline slide }}}
+.. R1
-In this tutorial, we shall learn
+Hello friends and welcome to the tutorial on 'Sets'.
- * sets
- * operations on sets
+.. L2
+{{{ Show the slide containing objectives }}}
+
+.. R2
+
+At the end of this tutorial, you will be able to,
+
+ 1. Create sets from lists.
+ #. Perform union, intersection and symmetric difference operations.
+ #. Check if a set is a subset of other.
+ #. Understand various similarities with lists like length and
+ containership.
+
+.. L3
+
+{{{ Switch to the pre-requisite slide }}}
+
+.. R3
+
+Before beginning this tutorial,we would suggest you to complete the
+tutorial on "Getting started with Lists"
+
+.. R5
+
+Now, What are sets?
Sets are data structures which contain unique elements. In other words,
duplicates are not allowed in sets.
+First let us invoke our ipython interpreter
+
+.. L5
+::
+
+ ipython
+
+.. R6
+
Lets look at how to input sets.
type
+
+.. L6
::
a_list = [1, 2, 1, 4, 5, 6, 2]
a = set(a_list)
a
+.. R7
+
We can see that duplicates are removed and the set contains only unique
-elements.
+elements. Now let us perform some operations on sets.
+For this, we shall first create a pair of sets
+
+.. L7
::
f10 = set([1, 2, 3, 5, 8])
p10 = set([2, 3, 5, 7])
+.. R8
+
f10 is the set of fibonacci numbers from 1 to 10.
p10 is the set of prime numbers from 1 to 10.
-Various operations that we do on sets are possible here also.
+Various operations can be performed on sets.For example,
The | (pipe) character stands for union
+
+.. L8
::
f10 | p10
-gives us the union of f10 and p10
+.. R9
-The & character stands for intersection.
+It gave the union of f10 and p10
+
+The '&' character stands for intersection.
+
+.. L9
::
f10 & p10
-gives the intersection
+.. R10
+
+It gave the intersection of f10 and p10
-similarly,
+similarly,f10 - p10 gives all the elements that are
+in f10 but not in p10
+
+.. L10
::
f10 - p10
-gives all the elements that are in f10 but not in p10
+.. R11
+
+and f10 ^ p10 gives all the elements in f10 union p10 but not
+in f10 intersection p10.
+.. L11
::
f10 ^ p10
-is all the elements in f10 union p10 but not in f10 intersection p10. In
-mathematical terms, it gives the symmectric difference.
+.. R12
+
+In mathematical terms, it gives the symmetric difference.
Sets also support checking of subsets.
+
+.. L12
::
b = set([1, 2])
b < f10
-gives a ``True`` since b is a proper subset of f10.
+.. R13
+
+It gives a ``True`` since b is a proper subset of f10.
Similarly,
+
+.. L13
::
f10 < f10
-gives a ``False`` since f10 is not a proper subset.
+.. R14
+
+It gives a ``False`` since f10 is not a proper subset.
hence the right way to do would be
+
+.. L14
::
f10 <= f10
-and we get a ``True`` since every set is a subset of itself.
+.. R15
+
+ we get a ``True`` since every set is a subset of itself.
Sets can be iterated upon just like lists and tuples.
+
+.. L15
::
for i in f10:
print i,
-prints the elements of f10.
+.. R16
+
+It prints the elements of f10.
+
+The length and containership check on sets is similar as in lists and
+tuples.
-The length and containership check on sets is similar as in lists and tuples.
+.. L16
::
len(f10)
-shows 5. And
+.. R17
+
+It shows 5. And
+
+.. L17
::
1 in f10
2 in f10
+.. R18
+
prints ``True`` and ``False`` respectively
-The order in which elements are organised in a set is not to be relied upon
-since sets do not support indexing. Hence, slicing and striding are not valid
-on sets.
+The order in which elements are organized in a set is not to be relied
+upon, since sets do not support indexing. Hence, slicing and striding
+are not valid on sets.
+
+Pause the video here, try out the following exercise and resume the video.
-{{{ Pause here and try out the following exercises }}}
+.. L18
-%% 1 %% Given a list of marks, marks = [20, 23, 22, 23, 20, 21, 23]
- list all the duplicates
+.. L19
+
+{{{ Show slide with exercise 1 }}}
+
+.. R19
+
+ Given a list of marks, marks = [20, 23, 22, 23, 20, 21, 23]
+ list all the duplicates
+
+.. L20
{{{ continue from paused state }}}
+{{{ Switch to the terminal }}}
+
+.. R20
-Duplicates marks are the marks left out when we remove each element of the
-list exactly one time.
+Duplicates marks are the marks left out when we remove each element of
+the list exactly one time.
+
+.. L21
::
@@ -146,24 +244,90 @@ list exactly one time.
for mark in marks_set:
marks.remove(mark)
- # we are now left with only duplicates in the list marks
+.. R21
+
+.. R22
+
+ We are now left with only duplicates in the list ``marks``
+Hence,
+
+.. L22
+::
+
duplicates = set(marks)
+ duplicates
+
+.. R23
+
+We obtained our required solution
+
+.. L23
+
+.. L24
{{{ Show summary slide }}}
-This brings us to the end of the tutorial.
-we have learnt
+.. R24
+
+This brings us to the end of the tutorial.In this tutorial,
+we have learnt to,
+
+ 1. Make sets from lists.
+ #. Perform union, intersection and symmetric difference operations.
+ by using the operators `|`, `&` and `^` respectively.
+ #. Check if a set is a subset of other using the `<` and `<=` operators.
+ #. Understand various similarities with lists like length and
+ containership.
+
+.. L25
+
+{{{Show self assessment questions slide}}}
+
+.. R25
+
+Here are some self assessment questions for you to solve
+
+1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a)
+
+ - set([1, 1, 2, 3, 3, 5, 5, 8])
+ - set([1, 2, 3, 5, 8])
+ - set([1, 2, 3, 3, 5, 5])
+ - Error
+
+2. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``.
+ How do you find the symmetric difference of these two sets?
+
+
+3. ``a`` is a set. how do you check if a variable ``b`` exists in ``a``?
+
+.. L26
+
+{{{solution of self assessment questions on slide}}}
+
+.. R26
+
+And the answers,
+
+1. set(a) will have all the common elements in the list ``a``, that is
+ ``set([1, 2, 3, 5, 8])``.
+
+2. To find the symmetric difference between two sets, we use
+ the operator `^`.
+::
+
+ odd ^ squares
+
+3. To check the containership, we say,
+::
+
+ b in a
- * How to make sets from lists
- * How to input sets
- * How to perform union, intersection and symmetric difference operations
- * How to check if a set is a subset of other
- * The various similarities with lists like length and containership
+.. L27
-{{{ Show the "sponsored by FOSSEE" slide }}}
+{{{ Show the Thank you slide }}}
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+.. R27
-Hope you have enjoyed and found it useful.
+Hope you have enjoyed this tutorial and found it useful.
Thank you!
diff --git a/sets/slides.org b/sets/slides.org
index 9f056d9..2869eca 100644
--- a/sets/slides.org
+++ b/sets/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Sets
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -29,43 +29,76 @@
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
-* Outline
- - Defining Sets
- - Operations on sets
-
-* Question 1
- Given a list of marks, ~marks = [20, 23, 22, 23, 20, 21, 23]~ list
- all the duplicates
-* Solution 1
- #+begin_src python
- marks = [20, 23, 22, 23, 20, 21, 23]
- marks_set = set(marks)
- for mark in marks_set:
- marks.remove(mark)
-
- # we are now left with only duplicates
- # in the list marks
- duplicates = set(marks)
-
- #+end_src
+*
+#+begin_latex
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Sets}
+\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,
+
+ - Create sets from lists.
+ - Perform union, intersection and symmetric difference operations.
+ - Check if a set is a subset of other.
+ - Understand various similarities with lists like length and containership.
+
+* Pre-requisite
+Spoken tutorial on -
+- Getting started with Lists
+* Exercise 1
+ - Given a list of marks,
+ ~marks = [20, 23, 22, 23, 20, 21, 23]~
+ List all the duplicates
* Summary
- You should now be able to --
- + make sets from lists
- + input sets directly
- + perform operations like union, intersection, symmetric difference
- + check if a subset of another
- + check containership, length and other properties similar to lists
-* Thank you!
+ In this tutorial, we have learnt to,
+
+ - Make sets from lists.
+ - Perform union, intersection and symmetric difference operations.
+ by using the operators `|`, `&` and ` \^ ` respectively.
+ - Check if a set is a subset of other using the `<` and `<=` operators.
+ - Understand various similarities with lists like length and containership.
+* Evaluation
+1. If ~a = [1, 1, 2, 3, 3, 5, 5, 8]~. What is set(a)?
+
+ - set([1, 1, 2, 3, 3, 5, 5, 8])
+ - set([1, 2, 3, 5, 8])
+ - set([1, 2, 3, 3, 5, 5])
+ - Error
+
+2. Given, ~odd = set([1, 3, 5, 7, 9])~ and ~squares = set([1, 4, 9, 16])~.
+ How do you find the symmetric difference of these two sets?
+
+
+3. ``a'' is a set. how do you check if a variable ``b'' exists in ``a''?
+* Solutions
+1. set([1, 2, 3, 5, 8])
+
+2. odd ^ squares
+
+3. b in a
+*
#+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/sets/slides.tex b/sets/slides.tex
index 945af18..ee3e5df 100644
--- a/sets/slides.tex
+++ b/sets/slides.tex
@@ -1,4 +1,4 @@
-% Created 2010-11-09 Tue 17:14
+% Created 2011-07-07 Thu 11:19
\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{Sets}
+\title{}
\author{FOSSEE}
\date{}
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}
-\maketitle
+
@@ -41,65 +41,119 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
-\begin{itemize}
-\item Defining Sets
-\item Operations on sets
-\end{itemize}
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Sets}
+\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}
- Given a list of marks, \texttt{marks = [20, 23, 22, 23, 20, 21, 23]} list
- all the duplicates
+ At the end of this tutorial, you will be able to,
+
+
+\begin{itemize}
+\item Create sets from lists.
+\item Perform union, intersection and symmetric difference operations.
+\item Check if a set is a subset of other.
+\item Understand various similarities with lists like length and containership.
+\end{itemize}
\end{frame}
-\begin{frame}[fragile]
-\frametitle{Solution 1}
+\begin{frame}
+\frametitle{Pre-requisite}
\label{sec-3}
-\lstset{language=Python}
-\begin{lstlisting}
-marks = [20, 23, 22, 23, 20, 21, 23]
-marks_set = set(marks)
-for mark in marks_set:
- marks.remove(mark)
-
-# we are now left with only duplicates
-# in the list marks
-duplicates = set(marks)
-\end{lstlisting}
+Spoken tutorial on -
+\begin{itemize}
+\item Getting started with Lists
+\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Summary}
+\frametitle{Exercise 1}
\label{sec-4}
- You should now be able to --
+
\begin{itemize}
-\item make sets from lists
-\item input sets directly
-\item perform operations like union, intersection, symmetric difference
-\item check if a subset of another
-\item check containership, length and other properties similar to lists
+\item Given a list of marks,
\end{itemize}
+ ~~~~~~~~~~~~\verb~marks = [20, 23, 22, 23, 20, 21, 23]~ \\
+\vspace{8pt}
+ ~~~~~~~~List all the duplicates.
\end{frame}
\begin{frame}
-\frametitle{Thank you!}
+\frametitle{Summary}
\label{sec-5}
+ In this tutorial, we have learnt to,
+
+
+\begin{itemize}
+\item Make sets from lists.
+\item Perform union, intersection and symmetric difference operations.
+ by using the operators `|', `\&' and `\textasciicircum' respectively.
+\item Check if a set is a subset of other using the `<'and `<=' operators.
+\item Understand various similarities with lists like length and containership.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Evaluation}
+\label{sec-6}
+
+
+\begin{enumerate}
+\item If \verb~a = [1, 1, 2, 3, 3, 5, 5, 8]~. What is set(a)?
+\vspace{3pt}
+\begin{itemize}
+\item set([1, 1, 2, 3, 3, 5, 5, 8])
+\item set([1, 2, 3, 5, 8])
+\item set([1, 2, 3, 3, 5, 5])
+\item Error
+\end{itemize}
+\vspace{6pt}
+\item Given, \verb~odd = set([1, 3, 5, 7, 9])~ and \verb~squares = set([1, 4, 9, 16])~. \\
+ How do you find the symmetric difference of these two sets?
+\vspace{15pt}
+\item ``a'' is a set. how do you check if a variable ``b'' exists in ``a''?
+\end{enumerate}
+\end{frame}
+\begin{frame}
+\frametitle{Solutions}
+\label{sec-7}
+
+
+\begin{enumerate}
+\item set([1, 2, 3, 5, 8])
+\vspace{12pt}
+\item odd \^{} squares
+\vspace{12pt}
+\item b in a
+\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