summaryrefslogtreecommitdiff
path: root/basic_python/slides
diff options
context:
space:
mode:
Diffstat (limited to 'basic_python/slides')
-rw-r--r--basic_python/slides/func.tex262
-rw-r--r--basic_python/slides/intro.tex477
-rw-r--r--basic_python/slides/io_files_parsing.tex239
-rw-r--r--basic_python/slides/strings_loops_lists.tex456
-rw-r--r--basic_python/slides/tmp.tex1
-rw-r--r--basic_python/slides/tuples_dicts_sets.tex256
6 files changed, 1691 insertions, 0 deletions
diff --git a/basic_python/slides/func.tex b/basic_python/slides/func.tex
new file mode 100644
index 0000000..eefd0d5
--- /dev/null
+++ b/basic_python/slides/func.tex
@@ -0,0 +1,262 @@
+\section{Functions}
+
+\begin{frame}[fragile]
+ \frametitle{Abstracting}
+ \begin{itemize}
+ \item Reduce duplication of code
+ \item Fewer lines of code and hence lesser scope for bugs
+ \item Re-usability of code, that's already been written
+ \item Use functions written by others, without exactly knowing how
+ they do, what they are doing
+ \item \alert{Enter Functions!}
+ \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{Defining functions}
+ \begin{itemize}
+ \item Consider the function \texttt{f(x) = x\textasciicircum{}2}
+ \item Let's write a Python function, equivalent to this
+ \end{itemize}
+ \begin{lstlisting}
+ def f(x):
+ return x*x
+
+ f(1)
+ f(2)
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{def} is a keyword
+ \item \texttt{f} is the name of the function
+ \item \texttt{x} the parameter of the function
+ \item \texttt{return} is a keyword; specifies what should be
+ returned
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Defining functions \ldots}
+ \begin{lstlisting}
+ def greet():
+ print "Hello World!"
+
+ greet()
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{greet} is a function that takes no arguments
+ \item Also, it is not returning anything explicitly
+ \item But implicitly, Python returns \texttt{None}
+ \end{itemize}
+ \begin{lstlisting}
+ def avg(a, b):
+ return (a + b)/2
+
+ avg(12, 10)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Doc-strings}
+ \begin{itemize}
+ \item It's highly recommended that all functions have documentation
+ \item We write a doc-string along with the function definition
+ \end{itemize}
+ \begin{lstlisting}
+ def avg(a, b):
+ """ avg takes two numbers as input
+ and returns their average"""
+
+ return (a + b)/2
+
+ avg?
+ greet?
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Returning multiple values}
+ \begin{itemize}
+ \item Return area and perimeter of circle, given radius
+ \item Function needs to return two values
+ \end{itemize}
+ \begin{lstlisting}
+ def circle(r):
+ """returns area and perimeter of a
+ circle given, the radius r"""
+
+ pi = 3.14
+ area = pi * r * r
+ perimeter = 2 * pi * r
+ return area, perimeter
+
+ circle(4)
+ a, p = circle(6)
+ print a
+ print p
+ \end{lstlisting}
+ \begin{itemize}
+ \item Any number of values can be returned
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{What? -- 1}
+ \begin{lstlisting}
+ def what( n ):
+ if n < 0: n = -n
+ while n > 0:
+ if n % 2 == 1:
+ return False
+ n /= 10
+ return True
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{What? -- 2}
+ \begin{lstlisting}
+ def what( n ):
+ i = 1
+ while i * i < n:
+ i += 1
+ return i * i == n, i
+ \end{lstlisting}
+\end{frame}
+
+\subsection*{Default \& Keyword Arguments}
+
+\begin{frame}[fragile]
+ \frametitle{Default arguments}
+ \begin{lstlisting}
+ round(2.484)
+ round(2.484, 2)
+
+ s.split() # split on spaces
+ s.split(';') # split on ';'
+
+ range(10) # returns numbers from 0 to 9
+ range(1, 10) # returns numbers from 1 to 9
+ range(1, 10, 2) # returns odd numbers from 1 to 9
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Default arguments \ldots}
+ \begin{lstlisting}
+ def welcome(greet, name="World"):
+ print greet, name
+
+ welcome("Hi", "Guido")
+ welcome("Hello")
+ \end{lstlisting}
+ \begin{itemize}
+ \item Arguments with default values, should be placed at the end
+ \item The following definition is \alert{WRONG}
+ \end{itemize}
+ \begin{lstlisting}
+ def welcome(name="World", greet):
+ print greet, name
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Keyword Arguments}
+ \begin{lstlisting}
+ def welcome(greet, name="World"):
+ print greet, name
+
+ welcome("Hello", "James")
+
+ welcome("Hi", name="Guido")
+
+ welcome(name="Guido", greet="Hey")
+
+ welcome(name="Guido", "Hey")
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Built-in functions}
+ \begin{itemize}
+ \item Variety of built-in functions are available
+ \item \texttt{abs, any, all, len, max, min}
+ \item \texttt{pow, range, sum, type}
+ \item Refer here:
+ \url{http://docs.python.org/library/functions.html}
+ \end{itemize}
+\end{frame}
+
+\subsection*{Variable Scope}
+
+\begin{frame}[fragile]
+ \frametitle{Arguments are local}
+ \begin{lstlisting}
+ def change(q):
+ q = 10
+ print q
+
+ change(1)
+ print q
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Variables inside function are local}
+ \begin{lstlisting}
+ n = 5
+ def change():
+ n = 10
+ print n
+ change()
+ print n
+ \end{lstlisting}
+ \begin{itemize}
+ \item Use the \texttt{global} statement to assign to global variables
+ \end{itemize}
+ \begin{lstlisting}
+ def change():
+ global n
+ n = 10
+ print n
+ change()
+ print n
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Mutable variables}
+ \begin{itemize}
+ \item Behavior is different when assigning to a list element/slice
+ \item Python looks up for the name, from innermost scope outwards,
+ until the name is found
+ \end{itemize}
+ \begin{lstlisting}
+ name = ['Mr.', 'Steve', 'Gosling']
+ def change_name():
+ name[0] = 'Dr.'
+ change_name()
+ print name
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Passing Arguments \ldots}
+ \begin{lstlisting}
+ n = 5
+ def change(n):
+ n = 10
+ print "n = %s inside change " %n
+ change(n)
+ print n
+ \end{lstlisting}
+
+ \begin{lstlisting}
+ name = ['Mr.', 'Steve', 'Gosling']
+ def change_name(n):
+ n[0] = 'Dr.'
+ print "n = %s inside change_name" %n
+ change_name(n)
+ print name
+ \end{lstlisting}
+\end{frame}
diff --git a/basic_python/slides/intro.tex b/basic_python/slides/intro.tex
new file mode 100644
index 0000000..34c20dd
--- /dev/null
+++ b/basic_python/slides/intro.tex
@@ -0,0 +1,477 @@
+\section{The Language}
+\begin{frame}[fragile]
+ \frametitle{Python!}
+ \begin{itemize}
+ \item Programming Language
+ \item Powerful, High-level, Interpreted, Multi-Platform
+ \item Elegant and highly readable syntax
+ \item Efficient high-level data structures
+ \end{itemize}
+ \begin{itemize}
+ \item Easy to learn
+ \item Allows to concentrate on the problem instead of the language
+ \item Increased Productivity
+ \end{itemize}
+ \begin{itemize}
+ \item Guido van Rossum -- BDFL
+ \item Conceived in December 1989
+ \item Named after ``Monty Python's Flying Circus'', a 70s comedy
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Why Python?}
+ \begin{itemize}
+ \item Extremely readable; Forces programmers to write readable code.
+ \item Interactive; Offers a very fast edit-test-debug cycle.
+ \item Doesn't get in your way; High-level data structures let you
+ focus on the problem
+ \item Handles memory management
+ \item Batteries included; Huge standard library for wide range of
+ tasks.
+ \item Object-oriented.
+ \item C, C++ and FORTRAN interfacing allows use of legacy code
+ \item Your time is more valuable than machine time!
+ \end{itemize}
+\end{frame}
+
+\section{The Interpreter}
+\begin{frame}[fragile]
+ \frametitle{Python interpreter}
+ \begin{itemize}
+ \item Let's get our hands dirty!
+ \item Start Python from your shell
+ \end{itemize}
+ \lstset{language=sh}
+ \begin{lstlisting}
+ $ python
+ \end{lstlisting} %$
+ \begin{lstlisting}
+Python 2.7.1 (r271:86832, Feb 21 2011, 01:28:26)
+[GCC 4.5.2 20110127 (prerelease)] on linux2
+Type "help", "copyright", "credits" or "license" for more information.
+>>>
+ \end{lstlisting}
+ \begin{itemize}
+ \item First line shows Python version (2.7.1)
+ \item \verb+>>>+ the interpreter's prompt
+ \item The interpreter is ready and waiting for your command!
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Hello World!}
+ \begin{itemize}
+ \item Type\texttt{print `Hello World'} and hitting enter
+ \end{itemize}
+ \begin{lstlisting}
+ >>> print 'Hello, World!'
+ Hello, World!
+ \end{lstlisting}
+ \begin{itemize}
+ \item The interpreter prints out the words \emph{Hello World}
+ \end{itemize}
+ \begin{itemize}
+ \item Hit \texttt{Ctrl-D} to exit the interpreter
+ \item We shall look at IPython, an enhanced interpreter
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Versions}
+ Before moving on \ldots
+ \begin{itemize}
+ \item Currently has two stable branches or versions, 2.x and 3.x
+ \item 3.x is not backward compatible
+ \item 3.x is deemed to be the future of Python
+ \item But, we shall stick to 2.x for this course
+ \item The ecosystem around Python 2.x hasn't yet moved to 3.x
+ \end{itemize}
+\end{frame}
+
+\subsection*{IPython}
+
+\begin{frame}[fragile]
+ \frametitle{Invoking IPython}
+ \begin{itemize}
+ \item An enhanced Python interpreter
+ \item Tab-completion, Easier access to help, Better history
+ \end{itemize}
+ \lstset{language=sh}
+ \begin{lstlisting}
+ $ ipython
+ \end{lstlisting} %$
+ \alert{If \texttt{ipython is not installed}, you need to install it!}
+ \begin{itemize}
+ \item The prompt is \texttt{In [1]:} instead of \verb+>>>+
+ \item \texttt{In} stands for input, 1 indicates the command number
+ \item Try \texttt{Hello World}
+ \end{itemize}
+ \begin{lstlisting}
+ In []: print 'Hello, World!'
+ Out[]: Hello, World!
+ \end{lstlisting}
+ {\tiny the numbers have been omitted to avoid confusion}
+ \begin{itemize}
+ \item Hit \texttt{Ctrl-D} to exit \texttt{ipython}; Say \texttt{y}
+ when prompted.
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Getting comfortable}
+ \begin{itemize}
+ \item Let's try some simple math to get comfortable
+ \end{itemize}
+ \begin{lstlisting}
+ In []: 1 + 2
+ In []: 5 - 3
+ In []: 7 - 4
+ In []: 6 * 5
+ \end{lstlisting}
+ \begin{itemize}
+ \item We get back the expected output
+ \item Output is displayed with an \texttt{Out[]}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{History \& Arrow Keys}
+ \begin{itemize}
+ \item Change the \texttt{print 1+2}
+ \item Use <UP-Arrow> to go back to \texttt{1+2} command
+ \item Use <LEFT-Arrow> to get to start of line; type \texttt{print }
+ \item Hit <RETURN>
+ \end{itemize}
+ \begin{lstlisting}
+ In []: print 1 + 2
+ \end{lstlisting}
+ \begin{itemize}
+ \item Now, change the previous command to \texttt{print 10*2}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Tab-Completion}
+ \begin{itemize}
+ \item We want to use \texttt{round} function
+ \item Type \texttt{ro}, and hit <TAB>
+ \end{itemize}
+ \begin{lstlisting}
+ In []: ro<TAB>
+ \end{lstlisting}
+ \begin{itemize}
+ \item Type \texttt{r}, and hit <TAB>
+ \item All possibilities are listed out, when ambiguous
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{?} for Help}
+ \begin{itemize}
+ \item To get help for \texttt{abs} function
+ \end{itemize}
+ \begin{lstlisting}
+ In []: abs?
+ In []: abs(19)
+ In []: abs(-10.5)
+ \end{lstlisting}
+ \begin{itemize}
+ \item Look at documentation for \texttt{round}
+ \item Optional arguments are denoted with square brackets
+ \texttt{[]}
+ \end{itemize}
+ \begin{lstlisting}
+ In []: round(2.484)
+ In []: round(2.484, 1)
+ In []: round(2.484, 2)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{?} for Help}
+ \begin{itemize}
+ \item To get help for \texttt{abs} function
+ \end{itemize}
+ \begin{lstlisting}
+ In []: abs?
+ In []: abs(19)
+ In []: abs(-10.5)
+ \end{lstlisting}
+ \begin{itemize}
+ \item Look at documentation for \texttt{round}
+ \item Optional arguments are denoted with square brackets
+ \texttt{[]}
+ \end{itemize}
+ \begin{lstlisting}
+ In []: round(2.484)
+ In []: round(2.484, 1)
+ In []: round(2.484, 2)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Interrupting}
+ \begin{lstlisting}
+ In []: round(2.484
+ ...:
+ \end{lstlisting}
+ \begin{itemize}
+ \item The \ldots prompt is the continuation prompt
+ \item It comes up, since we haven't completed previous command
+ \item Either complete by typing the missing \texttt{)}
+ \item OR hit \texttt{Ctrl-C} to interrupt the command
+ \end{itemize}
+ \begin{lstlisting}
+ In []: round(2.484
+ ...: ^C
+ \end{lstlisting}
+\end{frame}
+
+\section{Basic Datatypes and Operators}
+
+\begin{frame}[fragile]
+ \frametitle{Basic Datatypes}
+ \begin{itemize}
+ \item Numbers
+ \begin{itemize}
+ \item int
+ \item float
+ \item complex
+ \end{itemize}
+ \item Boolean
+ \item Sequence
+ \begin{itemize}
+ \item Strings
+ \item Lists
+ \item Tuples
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{int}}
+ \begin{lstlisting}
+ In []: a = 13
+ In []: a
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{a} is a variable of the \texttt{int} type
+ \item Use the \texttt{type} command to verify
+ \end{itemize}
+ \begin{lstlisting}
+ In []: type(a)
+ \end{lstlisting}
+ \begin{itemize}
+ \item Integers can be arbitrarily long
+ \end{itemize}
+ \begin{lstlisting}
+ In []: b = 9999999999999999999999999999
+ In []: b
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{float}}
+ \begin{lstlisting}
+ In []: p = 3.141592
+ In []: p
+ \end{lstlisting}
+ \begin{itemize}
+ \item Decimal numbers are represented using the \texttt{float} type
+ \item Notice the loss of precision
+ \item Floats have a fixed precision
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{complex}}
+ \begin{lstlisting}
+ In []: c = 3+4j
+ \end{lstlisting}
+ \begin{itemize}
+ \item A complex number with real part 3, imaginary part 4
+ \end{itemize}
+ \begin{lstlisting}
+ In []: c.real
+ In []: c.imag
+ In []: abs(c)
+ \end{lstlisting}
+ \begin{itemize}
+ \item It's a combination of two floats
+ \item \texttt{abs} gives the absolute value
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Operations on numbers}
+ \begin{lstlisting}
+ In []: 23 + 74
+ In []: 23 - 56
+ In []: 45 * 76
+
+ In []: 8 / 3
+ In []: 8.0 / 3
+ In []: float(8) / 3
+ \end{lstlisting}
+ \begin{itemize}
+ \item The first division is an integer division
+ \item To avoid integer division, at least one number should be float
+ \item \texttt{float} function is changing int to float
+ \end{itemize}
+ \begin{lstlisting}
+ In []: 87 % 6
+ In []: 7 ** 8
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{\%} is used for modulo operation
+ \item \texttt{**} is used for exponentiation
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Variables \& assignment}
+ \begin{itemize}
+ \item All the operations could be done on variables
+ \end{itemize}
+ \begin{lstlisting}
+ In []: a = 23
+ In []: b = 74
+ In []: a * b
+
+ In []: c = 8
+ In []: d = 8.0
+ In []: f = c / 3
+ \end{lstlisting}
+ \begin{itemize}
+ \item Last two commands show assignment
+ \end{itemize}
+ \begin{lstlisting}
+ In []: c = c / 3
+ \end{lstlisting}
+ An operation like the one above, may equivalently be written as
+ \begin{lstlisting}
+ In []: c /= 3
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Booleans \& Operations}
+ \begin{itemize}
+ \item All the operations could be done on variables
+ \end{itemize}
+ \begin{lstlisting}
+ In []: t = True
+ In []: t
+ In []: f = not t
+ In []: f
+ In []: f or t
+ In []: f and t
+ \end{lstlisting}
+ \begin{itemize}
+ \item Multiple operation in a single command
+ \item We use parenthesis for explicitly stating what we mean
+ \item No discussion of operator precedence
+ \end{itemize}
+ \begin{lstlisting}
+ In []: (f and t) or t
+ In []: f and (t or t)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Sequences}
+ \begin{itemize}
+ \item Hold a bunch of elements in a sequence
+ \item Elements are accessed based on position in the sequence
+ \item The sequence data-types
+ \begin{itemize}
+ \item str
+ \item list
+ \item tuple
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Strings, Lists \& Tuples}
+ \begin{itemize}
+ \item Anything withing quotes is a string
+ \end{itemize}
+ \begin{lstlisting}
+ In []: greet_str = "hello"
+ \end{lstlisting}
+ \begin{itemize}
+ \item Items enclosed in \texttt{[ ]} and separated by \texttt{,}s
+ constitute a list
+ \end{itemize}
+ \begin{lstlisting}
+ In []: num_list = [1, 2, 3, 4, 5, 6, 7, 8]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Items of a tuple are enclosed by \texttt{( )} instead of
+ \texttt{[ ]}
+ \end{itemize}
+ \begin{lstlisting}
+ In []: num_tuple = num_tuple = (1, 2, 3, 4, 5, 6, 7, 8)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Operations on Sequences}
+ \begin{itemize}
+ \item Accessing elements
+ \end{itemize}
+ \begin{lstlisting}
+ In []: num_list[2]
+ In []: num_tuple[2]
+ In []: greet_str[2]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Add two sequences of same type
+ \end{itemize}
+ \begin{lstlisting}
+ In []: num_list + [3, 4, 5, 6]
+ In []: greet_str + " world!"
+ \end{lstlisting}
+ \begin{itemize}
+ \item Get the length of a sequence
+ \end{itemize}
+ \begin{lstlisting}
+ In []: len(num_list)
+ In []: len(greet_str)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Operations on Sequences \ldots}
+ \begin{itemize}
+ \item Check for container-ship of elements
+ \end{itemize}
+ \begin{lstlisting}
+ In []: 3 in num_list
+ In []: 'h' in greet_str
+ In []: 'w' in greet_str
+ In []: 2 in num_tuple
+ \end{lstlisting}
+ \begin{itemize}
+ \item Finding maximum and minimum
+ \end{itemize}
+ \begin{lstlisting}
+ In []: max(num_list)
+ In []: min(greet_str)
+ \end{lstlisting}
+ \begin{itemize}
+ \item Slice a sequence
+ \end{itemize}
+ \begin{lstlisting}
+ In []: num_list[1:5]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Stride over a sequence
+ \end{itemize}
+ \begin{lstlisting}
+ In []: num_list[1:8:2]
+ \end{lstlisting}
+\end{frame}
+
diff --git a/basic_python/slides/io_files_parsing.tex b/basic_python/slides/io_files_parsing.tex
new file mode 100644
index 0000000..0fa030a
--- /dev/null
+++ b/basic_python/slides/io_files_parsing.tex
@@ -0,0 +1,239 @@
+\section{I/O}
+
+\begin{frame}[fragile]
+ \frametitle{Printing}
+ \begin{lstlisting}
+ a = "This is a string"
+ a
+ print a
+ \end{lstlisting}
+ \begin{itemize}
+ \item Both \texttt{a}, and \texttt{print a} are showing the value
+ \item What is the difference?
+ \item Typing \texttt{a} shows the value; \texttt{print a} prints it
+ \item Typing \texttt{a} shows the value only in interpreter
+ \item In a script, it has no effect.
+ \end{itemize}
+ \begin{lstlisting}
+ b = "A line \n New line"
+ b
+ print b
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{String formatting}
+ \begin{lstlisting}
+ x = 1.5
+ y = 2
+ z = "zed"
+ print "x is %2.1f y is %d z is %s" %(x, y, z)
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{print x} \& \texttt{print x,}}
+ \begin{itemize}
+ \item Open an editor
+ \item Type the following code
+ \item Save as \texttt{print\_example.py}
+ \end{itemize}
+ \begin{lstlisting}
+ print "Hello"
+ print "World"
+
+ print "Hello",
+ print "World"
+ \end{lstlisting}
+ \begin{itemize}
+ \item Run the script using \texttt{\% run print\_example.py}
+ \item \texttt{print x} adds a newline whereas \texttt{print x,} adds
+ a space
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{raw\_input}}
+ \begin{lstlisting}
+ ip = raw_input()
+ \end{lstlisting}
+ \begin{itemize}
+ \item The cursor is blinking; waiting for input
+ \item Type \texttt{an input} and hit <ENTER>
+ \end{itemize}
+ \begin{lstlisting}
+ print ip
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{raw\_input} \ldots}
+ \begin{lstlisting}
+ c = raw_input()
+ 5.6
+ c
+ type(c)
+ \end{lstlisting}
+ \begin{itemize}
+ \item \alert{\texttt{raw\_input} always takes a string}
+ \end{itemize}
+ \begin{lstlisting}
+ name = raw_input("Please enter your name: ")
+ George
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{raw\_input} can display a prompt string for the user
+ \end{itemize}
+\end{frame}
+
+\section{Files}
+
+\begin{frame}[fragile]
+ \frametitle{Opening files}
+ \begin{lstlisting}
+ pwd # present working directory
+ cd /home/fossee # go to location of the file
+ \end{lstlisting}
+ {\tiny The file is in our present working directory}
+ \begin{lstlisting}
+ f = open('pendulum.txt')
+ f
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{f} is a file object
+ \item Shows the mode in which the file is open (read mode)
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Reading the whole file}
+ \begin{lstlisting}
+ pend = f.read()
+ print pend
+ \end{lstlisting}
+ \begin{itemize}
+ \item We have read the whole file into the variable \texttt{pend}
+ \end{itemize}
+ \begin{lstlisting}
+ type(pend)
+ pend_list = pend.splitlines()
+ pend_list
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{pend} is a string variable
+ \item We can split it at the newline characters into a list of
+ strings
+ \item Close the file, when done; Also, if you want to read again
+ \end{itemize}
+ \begin{lstlisting}
+ f.close()
+ f
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Reading line-by-line}
+ \begin{lstlisting}
+ for line in open('pendulum.txt'):
+ print line
+ \end{lstlisting}
+ \begin{itemize}
+ \item The file object is an ``iterable''
+ \item We iterate over it and print each line
+ \item Instead of printing, collect lines in a list
+ \end{itemize}
+ \begin{lstlisting}
+ line_list = [ ]
+ for line in open('pendulum.txt'):
+ line_list.append(line)
+ \end{lstlisting}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{File parsing -- Problem}
+ \begin{lstlisting}
+ A;010002;ANAND R;058;037;42;35;40;212;P;;
+ \end{lstlisting}
+ \begin{itemize}
+ \item File with records like the one above is given
+ \item Each record has fields separated by ;
+ \item region code; roll number; name;
+ \item marks --- $1^{st}$ L; $2^{nd}$ L; math; science; social; total
+ \item pass/fail indicated by P/F; W if withheld and else empty
+ \end{itemize}
+
+ \begin{itemize}
+ \item We wish to calculate mean of math marks in region B
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Tokenization}
+ \begin{lstlisting}
+ line = "parse this string"
+ line.split()
+ \end{lstlisting}
+ \begin{itemize}
+ \item Original string is split on white-space (if no argument)
+ \item Returns a list of strings
+ \item It can be given an argument to split on that argrument
+ \end{itemize}
+ \begin{lstlisting}
+ record = "A;015163;JOSEPH RAJ S;083;042;47;AA;72;244;;;"
+ record.split(';')
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Tokenization \ldots}
+ \begin{itemize}
+ \item Since we split on commas, fields may have extra spaces at ends
+ \item We can strip out the spaces at the ends
+ \end{itemize}
+ \begin{lstlisting}
+ word = " B "
+ word.strip()
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{strip} is returning a new string
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{str} to \texttt{float}}
+ \begin{itemize}
+ \item After tokenizing, the marks we have are strings
+ \item We need numbers to perform math operations
+ \end{itemize}
+ \begin{lstlisting}
+ mark_str = "1.25"
+ mark = int(mark_str)
+ type(mark_str)
+ type(mark)
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{strip} is returning a new string
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{File parsing -- Solution}
+ \begin{lstlisting}
+ math_B = [] # empty list to store marks
+ for line in open("sslc1.txt"):
+ fields = line.split(";")
+
+ reg_code = fields[0]
+ reg_code_clean = reg_code.strip()
+
+ math_mark_str = fields[5]
+ math_mark = float(math_mark_str)
+
+ if reg_code == "B":
+ math_B.append(math_mark)
+
+ math_B_mean = sum(math_B) / len(math_B)
+ math_B_mean
+ \end{lstlisting}
+\end{frame}
diff --git a/basic_python/slides/strings_loops_lists.tex b/basic_python/slides/strings_loops_lists.tex
new file mode 100644
index 0000000..244fd95
--- /dev/null
+++ b/basic_python/slides/strings_loops_lists.tex
@@ -0,0 +1,456 @@
+\section{Strings}
+
+\begin{frame}[fragile]
+ \frametitle{What are Strings?}
+ \begin{itemize}
+ \item Anything quoted is a string
+ \item Single quotes, double quotes or triple single/double quotes
+ \item Any length --- single character, null string, \ldots
+ \end{itemize}
+ \begin{lstlisting}
+ 'This is a string'
+ "This is a string too'
+ '''This is a string as well'''
+ """This is also a string"""
+ '' # empty string
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Why so many?}
+ \begin{itemize}
+ \item Reduce the need for escaping
+ \end{itemize}
+ \begin{lstlisting}
+ "Python's strings are powerful!"
+ 'He said, "I love Python!"'
+ \end{lstlisting}
+ \begin{itemize}
+ \item Triple quoted strings can be multi-line
+ \item Used for doc-strings
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Assignment \& Operations}
+ \begin{lstlisting}
+ a = 'Hello'
+ b = 'World'
+ c = a + ', ' + b + '!'
+ \end{lstlisting}
+ \begin{itemize}
+ \item Strings can be multiplied with numbers
+ \end{itemize}
+ \begin{lstlisting}
+ a = 'Hello'
+ a * 5
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Accessing Elements}
+ \begin{lstlisting}
+ print a[0], a[4], a[-1], a[-4]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Can we change the elements?
+ \end{itemize}
+ \begin{lstlisting}
+ a[0] = 'H'
+ \end{lstlisting}
+ \begin{itemize}
+ \item Strings are immutable!
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Problem - Day of the Week?}
+ \begin{itemize}
+ \item Strings have methods to manipulate them
+ \end{itemize}
+ \begin{block}{Problem}
+ Given a list, \texttt{week}, containing names of the days of the
+ week and a string \texttt{s}, check if the string is a day of the
+ week. We should be able to check for any of the forms like,
+ \emph{sat, saturday, Sat, Saturday, SAT, SATURDAY}
+ \end{block}
+ \begin{itemize}
+ \item Get the first 3 characters of the string
+ \item Convert it all to lower case
+ \item Check for existence in the list, \texttt{week}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Slicing}
+ \begin{lstlisting}
+ q = "Hello World"
+ q[0:3]
+ q[:3]
+ q[3:]
+ q[:]
+ q[-1:1]
+ q[1:-1]
+ \end{lstlisting}
+ \begin{itemize}
+ \item One or both of the limits, is optional
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Striding}
+ \begin{lstlisting}
+ q[0:5:1]
+ q[0:5:2]
+ q[0:5:3]
+ q[0::2]
+ q[2::2]
+ q[::2]
+ q[5:0:-1]
+ q[::-1]
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{String Methods}
+ \begin{lstlisting}
+ s.lower()
+ s.upper()
+ s.<TAB>
+ \end{lstlisting}
+ \begin{itemize}
+ \item \alert{Strings are immutable!}
+ \item A new string is being returned
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Solution - Day of the Week?}
+ \begin{lstlisting}
+ s.lower()[:3] in week
+ \end{lstlisting}
+ OR
+ \begin{lstlisting}
+ s[:3].lower() in week
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{join} a list of strings}
+ \begin{itemize}
+ \item Given a list of strings
+ \item We wish to join them into a single string
+ \item Possibly, each string separated by a common token
+ \end{itemize}
+ \begin{lstlisting}
+ email_list = ["info@fossee.in",
+ "enquiries@fossee.in",
+ "help@fossee.in"]
+ \end{lstlisting}
+ \begin{lstlisting}
+ '; '.join(email_list)
+ ', '.join(email_list)
+ \end{lstlisting}
+\end{frame}
+
+\section{Conditionals}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{if-else} block}
+ \begin{lstlisting}
+ a = 5
+ if a % 2 == 0:
+ print "Even"
+ else:
+ print "Odd"
+ \end{lstlisting}
+ \begin{itemize}
+ \item A code block -- \texttt{:} and indentation
+ \item Exactly one block gets executed in the \texttt{if-else}
+ \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{if-elif-else}}
+ \begin{lstlisting}
+ if a > 0:
+ print "positive"
+ elif a < 0:
+ print "negative"
+ else:
+ print "zero"
+ \end{lstlisting}
+ \begin{itemize}
+ \item Only one block gets executed, depending on \texttt{a}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{else} is optional}
+ \begin{lstlisting}
+ if user == 'admin':
+ admin_Operations()
+ elif user == 'moderator':
+ moderator_operations()
+ elif user == 'client':
+ customer_operations()
+ \end{lstlisting}
+ \begin{itemize}
+ \item Note that there is no \texttt{else} block
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Ternary operator}
+ \begin{itemize}
+ \item \texttt{score\_str} is either \texttt{'AA'} or a string of one
+ of the numbers in the range 0 to 100.
+ \item We wish to convert the string to a number using \texttt{int}
+ \item Convert it to 0, when it is \texttt{'AA'}
+ \item \texttt{if-else} construct or the ternary operator
+ \end{itemize}
+ \begin{lstlisting}
+ if score_str != 'AA':
+ score = int(score_str)
+ else:
+ score = 0
+ \end{lstlisting}
+ \begin{lstlisting}
+ score = int(score_str) if score_str != 'AA' else 0
+ \end{lstlisting}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{pass}}
+ \begin{itemize}
+ \item \texttt{pass} is a syntactic filler
+ \item When a certain block has no statements, a \texttt{pass} is
+ thrown in
+ \item Mostly, when you want to get back to that part, later.
+ \end{itemize}
+\end{frame}
+
+\section{Loops}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{while}}
+ \begin{itemize}
+ \item Print squares of all odd numbers less than 10 using
+ \texttt{while}
+ \end{itemize}
+ \begin{lstlisting}
+ i = 1
+
+ while i<10:
+ print i*i
+ i += 2
+ \end{lstlisting}
+ \begin{itemize}
+ \item The loops runs as long as the condition is \texttt{True}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{for}}
+ \begin{itemize}
+ \item Print squares of all odd numbers less than 10 using
+ \texttt{for}
+ \end{itemize}
+ \begin{lstlisting}
+ for n in [1, 2, 3]:
+ print n
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{for} iterates over each element of a sequence
+ \end{itemize}
+ \begin{lstlisting}
+ for n in [1, 3, 5, 7, 9]:
+ print n*n
+
+ for n in range(1, 10, 2):
+ print n*n
+ \end{lstlisting}
+ \begin{itemize}
+ \item \alert{range([start,] stop[, step])}
+ \item Returns a list; Stop value is not included.
+ \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{break}}
+ \begin{itemize}
+ \item breaks out of the innermost loop.
+ \item Squares of odd numbers below 10 using \texttt{while} \&
+ \texttt{break}
+ \end{itemize}
+ \begin{lstlisting}
+ i = 1
+
+ while True:
+ print i*i
+ i += 2
+ if i<10:
+ break
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{\texttt{continue}}
+ \begin{itemize}
+ \item Skips execution of rest of the loop on current iteration
+ \item Jumps to the end of this iteration
+ \item Squares of all odd numbers below 10, not multiples of 3
+ \end{itemize}
+ \begin{lstlisting}
+ for n in range(1, 10, 2):
+ if n%3 == 0:
+ continue
+ print n*n
+ \end{lstlisting}
+\end{frame}
+
+
+\section{Lists}
+
+\begin{frame}[fragile]
+ \frametitle{Creating Lists}
+ \begin{lstlisting}
+ empty = []
+
+ p = ['spam', 'eggs', 100, 1.234]
+ q = [[4, 2, 3, 4], 'and', 1, 2, 3, 4]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Lists can be empty, with no elements in them
+ \item Lists can be heterogeneous -- every element of different kind
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Accessing Elements}
+ \begin{lstlisting}
+ print p[0], p[1], p[3]
+
+ print p[-1], p[-2], p[-4]
+ print p[10]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Indexing starts from 0
+ \item Indexes can be negative
+ \item Indexes should be in the valid range
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Accessing Elements \& length}
+ \begin{lstlisting}
+ print p[0], p[1], p[3]
+
+ print p[-1], p[-2], p[-4]
+ print len(p)
+ print p[10]
+ \end{lstlisting}
+ \begin{itemize}
+ \item Indexing starts from 0
+ \item Indexes can be negative
+ \item Indexes should be within the \texttt{range(0, len(p))}
+ \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{Adding \& Removing Elements}
+ \begin{itemize}
+ \item The append method adds elements to the end of the list
+ \end{itemize}
+ \begin{lstlisting}
+ p.append('onemore')
+ p
+ p.append([1, 6])
+ p
+ \end{lstlisting}
+ \begin{itemize}
+ \item Elements can be removed based on their index OR
+ \item based on the value of the element
+ \end{itemize}
+ \begin{lstlisting}
+ del p[1]
+ p.remove(100)
+ \end{lstlisting}
+ \begin{itemize}
+ \item \alert{When removing by value, first element is removed}
+ \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{Concatenating lists}
+ \begin{lstlisting}
+ a = [1, 2, 3, 4]
+ b = [4, 5, 6, 7]
+ a + b
+ print a+b, a, b
+ \end{lstlisting}
+ \begin{itemize}
+ \item A new list is returned; None of the original lists change
+ \end{itemize}
+ \begin{lstlisting}
+ c = a + b
+ c
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Slicing \& Striding}
+ \begin{lstlisting}
+ primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
+ primes[4:8]
+ primes[:4]
+
+ num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
+ num[1:10:2]
+ num[:10]
+ num[10:]
+ num[::2]
+ num[::-1]
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Sorting}
+ \begin{lstlisting}
+ a = [5, 1, 6, 7, 7, 10]
+ a.sort()
+ a
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{sort} method sorts the list in-place
+ \item Use \texttt{sorted} if you require a new list
+ \end{itemize}
+ \begin{lstlisting}
+ a = [5, 1, 6, 7, 7, 10]
+ sorted(a)
+ a
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Reversing}
+ \begin{lstlisting}
+ a = [5, 1, 6, 7, 7, 10]
+ a.reverse()
+ a
+ \end{lstlisting}
+ \begin{itemize}
+ \item \texttt{reverse} method reverses the list in-place
+ \item Use \texttt{[::-1]} if you require a new list
+ \end{itemize}
+ \begin{lstlisting}
+ a = [5, 1, 6, 7, 7, 10]
+ a[::-1]
+ a
+ \end{lstlisting}
+\end{frame}
diff --git a/basic_python/slides/tmp.tex b/basic_python/slides/tmp.tex
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/basic_python/slides/tmp.tex
@@ -0,0 +1 @@
+
diff --git a/basic_python/slides/tuples_dicts_sets.tex b/basic_python/slides/tuples_dicts_sets.tex
new file mode 100644
index 0000000..29dadba
--- /dev/null
+++ b/basic_python/slides/tuples_dicts_sets.tex
@@ -0,0 +1,256 @@
+\section{Tuples}
+
+\begin{frame}[fragile]
+ \frametitle{Tuples -- Initialization}
+ \begin{lstlisting}
+ t = (1, 2.5, "hello", -4, "world", 1.24, 5)
+ t
+ \end{lstlisting}
+ \begin{itemize}
+ \item It is not always necessary to use parenthesis
+ \end{itemize}
+ \begin{lstlisting}
+ a = 1, 2, 3
+ b = 1,
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Indexing}
+ \begin{lstlisting}
+ t[3]
+ t[1:5:2]
+ t[2] = "Hello"
+ \end{lstlisting}
+ \begin{itemize}
+ \item \alert{Tuples are immutable!}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Swapping values}
+ \begin{lstlisting}
+ a = 5
+ b = 7
+
+ temp = a
+ a = b
+ b = temp
+ \end{lstlisting}
+ \begin{itemize}
+ \item Here's the Pythonic way of doing it
+ \end{itemize}
+ \begin{lstlisting}
+ a, b = b, a
+ \end{lstlisting}
+ \begin{itemize}
+ \item The variables can be of different data-types
+ \end{itemize}
+ \begin{lstlisting}
+ a = 2.5
+ b = "hello"
+ a, b = b, a
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Tuple packing \& unpacking}
+ \begin{lstlisting}
+ 5,
+
+ 5, "hello", 2.5
+ \end{lstlisting}
+ \begin{itemize}
+ \item Tuple packing and unpacking, when swapping
+ \end{itemize}
+ \begin{lstlisting}
+ a, b = b, a
+ \end{lstlisting}
+\end{frame}
+
+\section{Dictionaries}
+
+\begin{frame}[fragile]
+ \frametitle{Creating Dictionaries}
+ \begin{lstlisting}
+ mt_dict = {}
+
+ extensions = {'jpg' : 'JPEG Image',
+ 'py' : 'Python script',
+ 'html' : 'Html document',
+ 'pdf' : 'Portable Document Format'}
+
+ extensions
+ \end{lstlisting}
+ \begin{itemize}
+ \item Key-Value pairs
+ \item \alert{ No ordering of keys! }
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Accessing Elements}
+ \begin{lstlisting}
+ print extensions['jpg']
+ \end{lstlisting}
+ \begin{itemize}
+ \item Values can be accessed using keys
+ \end{itemize}
+ \begin{lstlisting}
+ print extensions['zip']
+ \end{lstlisting}
+ \begin{itemize}
+ \item Values of non-existent keys cannot, obviously, be accessed
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Adding \& Removing Elements}
+ \begin{itemize}
+ \item Adding a new key-value pair
+ \end{itemize}
+ \begin{lstlisting}
+ extensions['cpp'] = 'C++ code'
+ extensions
+ \end{lstlisting}
+ \begin{itemize}
+ \item Deleting a key-value pair
+ \end{itemize}
+ \begin{lstlisting}
+ del extension['pdf']
+ extensions
+ \end{lstlisting}
+ \begin{itemize}
+ \item Assigning to existing key, modifies the value
+ \end{itemize}
+ \begin{lstlisting}
+ extensions['cpp'] = 'C++ source code'
+ extensions
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Containership}
+ \begin{lstlisting}
+ 'py' in extensions
+ 'odt' in extensions
+ \end{lstlisting}
+ \begin{itemize}
+ \item Allow checking for container-ship of keys; NOT values
+ \item Use the \texttt{in} keyword to check for container-ship
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Lists of Keys and Values}
+ \begin{lstlisting}
+ extensions.keys()
+ extensions.values()
+ \end{lstlisting}
+ \begin{itemize}
+ \item Note that the order of the keys and values match
+ \item That can be relied upon and used
+ \end{itemize}
+ \begin{lstlisting}
+ for each in extensions.keys():
+ print each, "-->", extensions[each]
+ \end{lstlisting}
+\end{frame}
+
+\section{Sets}
+
+\begin{frame}[fragile]
+ \frametitle{Creating Sets}
+ \begin{lstlisting}
+ a_list = [1, 2, 1, 4, 5, 6, 2]
+ a = set(a_list)
+ a
+ \end{lstlisting}
+ \begin{itemize}
+ \item Conceptually identical to the sets in mathematics
+ \item Duplicate elements not allowed
+ \item No ordering of elements exists
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Operations on Sets}
+ \begin{lstlisting}
+ f10 = set([1, 2, 3, 5, 8])
+ p10 = set([2, 3, 5, 7])
+ \end{lstlisting}
+ \begin{itemize}
+ \item Mathematical operations performed on sets, can be performed
+ \end{itemize}
+ \begin{itemize}
+ \item Union
+ \begin{lstlisting}
+ f10 | p10
+ \end{lstlisting}
+ \item Intersection
+ \begin{lstlisting}
+ f10 & p10
+ \end{lstlisting}
+ \item Difference
+ \begin{lstlisting}
+ f10 - p10
+ \end{lstlisting}
+ \item Symmetric Difference
+ \begin{lstlisting}
+ f10 ^ p10
+ \end{lstlisting}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Sub-sets}
+ \begin{itemize}
+ \item Proper Subset
+ \begin{lstlisting}
+ b = set([1, 2])
+ b < f10
+ \end{lstlisting}
+ \item Subsets
+ \begin{lstlisting}
+ f10 <= f10
+ \end{lstlisting}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Elements of sets}
+ \begin{itemize}
+ \item Containership
+ \begin{lstlisting}
+ 1 in f10
+ 4 in f10
+ \end{lstlisting}
+ \item Iterating over elements
+ \begin{lstlisting}
+ for i in f10:
+ print i,
+ \end{lstlisting}
+ \item Subsets
+ \begin{lstlisting}
+ f10 <= f10
+ \end{lstlisting}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Sets -- Example}
+ \begin{block}{}
+ Given a list of marks, \texttt{[20, 23, 22, 23, 20, 21, 23]} list
+ all the duplicates
+ \end{block}
+ \begin{lstlisting}
+ marks = [20, 23, 22, 23, 20, 21, 23]
+ marks_set = set(marks)
+ for mark in marks_set:
+ marks.remove(mark)
+
+ # left with only duplicates
+ duplicates = set(marks)
+ \end{lstlisting}
+\end{frame}
+