summaryrefslogtreecommitdiff
path: root/slides
diff options
context:
space:
mode:
Diffstat (limited to 'slides')
-rw-r--r--slides/advanced_python/images/L-Tsq.pngbin0 -> 27326 bytes
-rw-r--r--slides/advanced_python/images/bar.pngbin0 -> 14049 bytes
-rw-r--r--slides/advanced_python/images/cosine.pngbin0 -> 47888 bytes
-rw-r--r--slides/advanced_python/images/epid.pngbin0 -> 19554 bytes
-rw-r--r--slides/advanced_python/images/fsolve.pngbin0 -> 20617 bytes
-rw-r--r--slides/advanced_python/images/loglog.pngbin0 -> 20208 bytes
-rw-r--r--slides/advanced_python/images/lst-sq-fit.pngbin0 -> 30317 bytes
-rw-r--r--slides/advanced_python/images/ode.pngbin0 -> 59610 bytes
-rw-r--r--slides/advanced_python/images/overlaid.pngbin0 -> 65633 bytes
-rw-r--r--slides/advanced_python/images/pie.pngbin0 -> 49559 bytes
-rw-r--r--slides/advanced_python/images/plot.pngbin0 -> 26100 bytes
-rw-r--r--slides/advanced_python/images/roots.pngbin0 -> 20654 bytes
-rw-r--r--slides/advanced_python/images/scatter.pngbin0 -> 14917 bytes
-rw-r--r--slides/advanced_python/images/sine.pngbin0 -> 42508 bytes
-rw-r--r--slides/advanced_python/images/slice.pngbin0 -> 12825 bytes
-rw-r--r--slides/advanced_python/images/squares.pngbin0 -> 480 bytes
-rw-r--r--slides/advanced_python/images/subplot.pngbin0 -> 41041 bytes
-rw-r--r--slides/basic_python/data/sslc1.txt.gzbin0 -> 2981707 bytes
-rw-r--r--slides/basic_python/func.tex162
-rw-r--r--slides/basic_python/intro.tex8
-rw-r--r--slides/basic_python/io_files_parsing.tex69
-rw-r--r--slides/basic_python/python.tex10
-rw-r--r--slides/basic_python/strings_loops_lists.tex152
-rw-r--r--slides/basic_python/tmp.tex1
-rw-r--r--slides/basic_python/tuples_dicts_sets.tex78
25 files changed, 243 insertions, 237 deletions
diff --git a/slides/advanced_python/images/L-Tsq.png b/slides/advanced_python/images/L-Tsq.png
new file mode 100644
index 0000000..cc1a454
--- /dev/null
+++ b/slides/advanced_python/images/L-Tsq.png
Binary files differ
diff --git a/slides/advanced_python/images/bar.png b/slides/advanced_python/images/bar.png
new file mode 100644
index 0000000..cee54fb
--- /dev/null
+++ b/slides/advanced_python/images/bar.png
Binary files differ
diff --git a/slides/advanced_python/images/cosine.png b/slides/advanced_python/images/cosine.png
new file mode 100644
index 0000000..2b15a32
--- /dev/null
+++ b/slides/advanced_python/images/cosine.png
Binary files differ
diff --git a/slides/advanced_python/images/epid.png b/slides/advanced_python/images/epid.png
new file mode 100644
index 0000000..e1c7e08
--- /dev/null
+++ b/slides/advanced_python/images/epid.png
Binary files differ
diff --git a/slides/advanced_python/images/fsolve.png b/slides/advanced_python/images/fsolve.png
new file mode 100644
index 0000000..0108215
--- /dev/null
+++ b/slides/advanced_python/images/fsolve.png
Binary files differ
diff --git a/slides/advanced_python/images/loglog.png b/slides/advanced_python/images/loglog.png
new file mode 100644
index 0000000..824b9f1
--- /dev/null
+++ b/slides/advanced_python/images/loglog.png
Binary files differ
diff --git a/slides/advanced_python/images/lst-sq-fit.png b/slides/advanced_python/images/lst-sq-fit.png
new file mode 100644
index 0000000..7e9dfe2
--- /dev/null
+++ b/slides/advanced_python/images/lst-sq-fit.png
Binary files differ
diff --git a/slides/advanced_python/images/ode.png b/slides/advanced_python/images/ode.png
new file mode 100644
index 0000000..c76a483
--- /dev/null
+++ b/slides/advanced_python/images/ode.png
Binary files differ
diff --git a/slides/advanced_python/images/overlaid.png b/slides/advanced_python/images/overlaid.png
new file mode 100644
index 0000000..41e1891
--- /dev/null
+++ b/slides/advanced_python/images/overlaid.png
Binary files differ
diff --git a/slides/advanced_python/images/pie.png b/slides/advanced_python/images/pie.png
new file mode 100644
index 0000000..7791e54
--- /dev/null
+++ b/slides/advanced_python/images/pie.png
Binary files differ
diff --git a/slides/advanced_python/images/plot.png b/slides/advanced_python/images/plot.png
new file mode 100644
index 0000000..89cbc46
--- /dev/null
+++ b/slides/advanced_python/images/plot.png
Binary files differ
diff --git a/slides/advanced_python/images/roots.png b/slides/advanced_python/images/roots.png
new file mode 100644
index 0000000..c13a1a4
--- /dev/null
+++ b/slides/advanced_python/images/roots.png
Binary files differ
diff --git a/slides/advanced_python/images/scatter.png b/slides/advanced_python/images/scatter.png
new file mode 100644
index 0000000..66bd5d8
--- /dev/null
+++ b/slides/advanced_python/images/scatter.png
Binary files differ
diff --git a/slides/advanced_python/images/sine.png b/slides/advanced_python/images/sine.png
new file mode 100644
index 0000000..7667886
--- /dev/null
+++ b/slides/advanced_python/images/sine.png
Binary files differ
diff --git a/slides/advanced_python/images/slice.png b/slides/advanced_python/images/slice.png
new file mode 100644
index 0000000..7f53d2a
--- /dev/null
+++ b/slides/advanced_python/images/slice.png
Binary files differ
diff --git a/slides/advanced_python/images/squares.png b/slides/advanced_python/images/squares.png
new file mode 100644
index 0000000..ee102e6
--- /dev/null
+++ b/slides/advanced_python/images/squares.png
Binary files differ
diff --git a/slides/advanced_python/images/subplot.png b/slides/advanced_python/images/subplot.png
new file mode 100644
index 0000000..2c1a662
--- /dev/null
+++ b/slides/advanced_python/images/subplot.png
Binary files differ
diff --git a/slides/basic_python/data/sslc1.txt.gz b/slides/basic_python/data/sslc1.txt.gz
new file mode 100644
index 0000000..5cd0ecc
--- /dev/null
+++ b/slides/basic_python/data/sslc1.txt.gz
Binary files differ
diff --git a/slides/basic_python/func.tex b/slides/basic_python/func.tex
index b66be06..2d9a346 100644
--- a/slides/basic_python/func.tex
+++ b/slides/basic_python/func.tex
@@ -39,11 +39,11 @@
\begin{frame}[fragile]
\frametitle{Defining functions \ldots}
\begin{lstlisting}
- In[]: def greet():
- ....: print "Hello World!"
+ In[]: def greet():
+ ....: print "Hello World!"
....:
- In[]: greet()
+ In[]: greet()
\end{lstlisting}
\begin{itemize}
\item \texttt{greet} is a function that takes no arguments
@@ -51,11 +51,11 @@
\item But implicitly, Python returns \texttt{None}
\end{itemize}
\begin{lstlisting}
- In[]: def avg(a, b):
- ....: return (a + b)/2
+ In[]: def avg(a, b):
+ ....: return (a + b)/2
....:
- In[]: avg(12, 10)
+ In[]: avg(12, 10)
\end{lstlisting}
\end{frame}
@@ -66,15 +66,15 @@
\item We write a doc-string along with the function definition
\end{itemize}
\begin{lstlisting}
- In[]: def avg(a, b):
- """ avg takes two numbers as input
- and returns their average"""
+ In[]: def avg(a, b):
+ """ avg takes two numbers as input
+ and returns their average"""
- ....: return (a + b)/2
+ ....: return (a + b)/2
....:
- In[]: avg?
- In[]: greet?
+ In[]: avg?
+ In[]: greet?
\end{lstlisting}
\end{frame}
@@ -85,20 +85,20 @@
\item Function needs to return two values
\end{itemize}
\begin{lstlisting}
- In[]: 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
+ In[]: 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
....:
- In[]: circle(4)
- In[]: a, p = circle(6)
- In[]: print a
- In[]: print p
+ In[]: circle(4)
+ In[]: a, p = circle(6)
+ In[]: print a
+ In[]: print p
\end{lstlisting}
\begin{itemize}
\item Any number of values can be returned
@@ -108,13 +108,13 @@
\begin{frame}[fragile]
\frametitle{What? -- 1}
\begin{lstlisting}
- In[]: def what( n ):
- ....: if n < 0: n = -n
- ....: while n > 0:
- ....: if n % 2 == 1:
- ....: return False
- ....: n /= 10
- ....: return True
+ In[]: 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}
@@ -122,11 +122,11 @@
\begin{frame}[fragile]
\frametitle{What? -- 2}
\begin{lstlisting}
- In[]: def what( n ):
- ....: i = 1
- ....: while i * i < n:
- ....: i += 1
- ....: return i * i == n, i
+ In[]: def what( n ):
+ ....: i = 1
+ ....: while i * i < n:
+ ....: i += 1
+ ....: return i * i == n, i
....:
\end{lstlisting}
\end{frame}
@@ -139,8 +139,8 @@
In[]: round(2.484)
In[]: round(2.484, 2)
- In[]: s.split() # split on spaces
- In[]: s.split(';') # split on ';'
+ In[]: s.split() # split on spaces
+ In[]: s.split(';') # split on ';'
In[]: range(10) # returns numbers from 0 to 9
In[]: range(1, 10) # returns numbers from 1 to 9
@@ -151,8 +151,8 @@
\begin{frame}[fragile]
\frametitle{Default arguments \ldots}
\begin{lstlisting}
- In[]: def welcome(greet, name="World"):
- ....: print greet, name
+ In[]: def welcome(greet, name="World"):
+ ....: print greet, name
....:
In[]: welcome("Hi", "Guido")
@@ -163,8 +163,8 @@
\item The following definition is \alert{WRONG}
\end{itemize}
\begin{lstlisting}
- In[]: def welcome(name="World", greet):
- ....: print greet, name
+ In[]: def welcome(name="World", greet):
+ ....: print greet, name
....:
\end{lstlisting}
\end{frame}
@@ -172,17 +172,17 @@
\begin{frame}[fragile]
\frametitle{Keyword Arguments}
\begin{lstlisting}
- In[]: def welcome(greet, name="World"):
- ....: print greet, name
+ In[]: def welcome(greet, name="World"):
+ ....: print greet, name
....:
- In[]: welcome("Hello", "James")
+ In[]: welcome("Hello", "James")
In[]: welcome("Hi", name="Guido")
In[]: welcome(name="Guido", greet="Hey")
- In[]: welcome(name="Guido", "Hey")
+ In[]: welcome(name="Guido", "Hey")
\end{lstlisting}
\end{frame}
@@ -207,33 +207,21 @@
....: print q
....:
- In[]: change(1)
- In[]: print q
+ In[]: change(1)
+ In[]: print q
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Variables inside function are local}
\begin{lstlisting}
- In[]: n = 5
- In[]: def change():
- ....: n = 10
- ....: print n
+ In[]: n = 5
+ In[]: def change():
+ ....: n = 10
+ ....: print n
....:
- In[]: change()
- In[]: print n
- \end{lstlisting}
- \begin{itemize}
- \item Use the \texttt{global} statement to assign to global variables
- \end{itemize}
- \begin{lstlisting}
- In[]: def change():
- ....: global n
- ....: n = 10
- ....: print n
- ....:
- In[]: change()
- In[]: print n
+ In[]: change()
+ In[]: print n
\end{lstlisting}
\end{frame}
@@ -243,13 +231,13 @@
\item Use the \texttt{global} statement to assign to global variables
\end{itemize}
\begin{lstlisting}
- In[]: def change():
- ....: global n
- ....: n = 10
- ....: print n
+ In[]: def change():
+ ....: global n
+ ....: n = 10
+ ....: print n
....:
- In[]: change()
- In[]: print n
+ In[]: change()
+ In[]: print n
\end{lstlisting}
\end{frame}
@@ -261,9 +249,9 @@
until the name is found
\end{itemize}
\begin{lstlisting}
- In[]: name = ['Mr.', 'Steve', 'Gosling']
- In[]: def change_name():
- ....: name[0] = 'Dr.'
+ In[]: name = ['Mr.', 'Steve', 'Gosling']
+ In[]: def change_name():
+ ....: name[0] = 'Dr.'
....:
In[]: change_name()
In[]: print name
@@ -273,22 +261,22 @@
\begin{frame}[fragile]
\frametitle{Passing Arguments \ldots}
\begin{lstlisting}
- In[]: n = 5
- In[]: def change(n):
- ....: n = 10
- ....: print "n = %s inside change " %n
+ In[]: n = 5
+ In[]: def change(n):
+ ....: n = 10
+ ....: print "n = %s inside change " %n
....:
- In[]: change(n)
- In[]: print n
+ In[]: change(n)
+ In[]: print n
\end{lstlisting}
\begin{lstlisting}
- In[]: name = ['Mr.', 'Steve', 'Gosling']
- In[]: def change_name(n):
- ....: n[0] = 'Dr.'
- ....: print "n = %s inside change_name" %n
+ In[]: name = ['Mr.', 'Steve', 'Gosling']
+ In[]: def change_name(n):
+ ....: n[0] = 'Dr.'
+ ....: print "n = %s inside change_name" %n
....:
- In[]: change_name(name)
- In[]: print name
+ In[]: change_name(name)
+ In[]: print name
\end{lstlisting}
\end{frame}
diff --git a/slides/basic_python/intro.tex b/slides/basic_python/intro.tex
index 52be064..a98cc19 100644
--- a/slides/basic_python/intro.tex
+++ b/slides/basic_python/intro.tex
@@ -22,14 +22,14 @@
\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 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.
+ 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}
diff --git a/slides/basic_python/io_files_parsing.tex b/slides/basic_python/io_files_parsing.tex
index cb46cbe..f766f1c 100644
--- a/slides/basic_python/io_files_parsing.tex
+++ b/slides/basic_python/io_files_parsing.tex
@@ -3,9 +3,9 @@
\begin{frame}[fragile]
\frametitle{Printing}
\begin{lstlisting}
- In[]: a = "This is a string"
- In[]: a
- In[]: print a
+ In[]: a = "This is a string"
+ In[]: a
+ In[]: print a
\end{lstlisting}
\begin{itemize}
\item Both \texttt{a}, and \texttt{print a} are showing the value
@@ -15,19 +15,20 @@
\item In a script, it has no effect.
\end{itemize}
\begin{lstlisting}
- In[]: b = "A line \n New line"
- In[]: b
- In[]: print b
+ In[]: b = "A line \n New line"
+ In[]: b
+ In[]: print b
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{String formatting}
+ \small
\begin{lstlisting}
In[]: x = 1.5
- In[]: y = 2
- In[]: z = "zed"
- In[]: print "x is %2.1f y is %d z is %s" %(x, y, z)
+ In[]: y = 2
+ In[]: z = "zed"
+ In[]: print "x is %2.1f y is %d z is %s" %(x, y, z)
\end{lstlisting}
\end{frame}
@@ -42,7 +43,7 @@
In[]: print "Hello"
In[]: print "World"
- In[]: print "Hello",
+ In[]: print "Hello",
In[]: print "World"
\end{lstlisting}
\begin{itemize}
@@ -55,7 +56,7 @@
\begin{frame}[fragile]
\frametitle{\texttt{raw\_input}}
\begin{lstlisting}
- In[]: ip = raw_input()
+ In[]: ip = raw_input()
\end{lstlisting}
\begin{itemize}
\item The cursor is blinking; waiting for input
@@ -69,17 +70,17 @@
\begin{frame}[fragile]
\frametitle{\texttt{raw\_input} \ldots}
\begin{lstlisting}
- In[]: c = raw_input()
- In[]: 5.6
+ In[]: c = raw_input()
+ 5.6
In[]: c
- In[]: type(c)
+ In[]: type(c)
\end{lstlisting}
\begin{itemize}
\item \alert{\texttt{raw\_input} always takes a string}
\end{itemize}
\begin{lstlisting}
- In[]: name = raw_input("Please enter your name: ")
- George
+ In[]: name = raw_input("Enter your name: ")
+ Enter your name: George
\end{lstlisting}
\begin{itemize}
\item \texttt{raw\_input} can display a prompt string for the user
@@ -126,7 +127,7 @@
\item Close the file, when done; Also, if you want to read again
\end{itemize}
\begin{lstlisting}
- In[]: f.close()
+ In[]: f.close()
In[]: f
\end{lstlisting}
\end{frame}
@@ -157,7 +158,7 @@
\end{lstlisting}
\begin{itemize}
\item File with records like the one above is given
- \item Each record has fields separated by ;
+ \item Each record has fields separated by \verb+;+
\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
@@ -171,8 +172,8 @@
\begin{frame}[fragile]
\frametitle{Tokenization}
\begin{lstlisting}
- In[]: line = "parse this string"
- In[]: line.split()
+ In[]: line = "parse this string"
+ In[]: line.split()
\end{lstlisting}
\begin{itemize}
\item Original string is split on white-space (if no argument)
@@ -180,7 +181,7 @@
\item It can be given an argument to split on that argrument
\end{itemize}
\begin{lstlisting}
- In[]: record = "A;015163;JOSEPH RAJ S;083;042;47;AA;72;244;;;"
+ In[]: record = "A;015163;JOSEPH RAJ S;083;042;47;AA;72;244;;;"
In[]: record.split(';')
\end{lstlisting}
\end{frame}
@@ -207,9 +208,9 @@
\item We need numbers to perform math operations
\end{itemize}
\begin{lstlisting}
- In[]: mark_str = "1.25"
- In[]: mark = int(mark_str)
- In[]: type(mark_str)
+ In[]: mark_str = "1.25"
+ In[]: mark = int(mark_str)
+ In[]: type(mark_str)
In[]: type(mark)
\end{lstlisting}
\begin{itemize}
@@ -220,20 +221,20 @@
\begin{frame}[fragile]
\frametitle{File parsing -- Solution}
\begin{lstlisting}
- In[]: math_B = [] # empty list to store marks
+ In[]: math_B = [] # empty list to store marks
In[]: for line in open("sslc1.txt"):
- ....: fields = line.split(";")
+ ....: fields = line.split(";")
- ....: reg_code = fields[0]
- ....: reg_code_clean = reg_code.strip()
+ ....: reg_code = fields[0]
+ ....: reg_code_clean = reg_code.strip()
- ....: math_mark_str = fields[5]
- ....: math_mark = float(math_mark_str)
+ ....: math_mark_str = fields[5]
+ ....: math_mark = float(math_mark_str)
- ....: if reg_code == "B":
- ....: math_B.append(math_mark)
+ ....: if reg_code == "B":
+ ....: math_B.append(math_mark)
- In[]: math_B_mean = sum(math_B) / len(math_B)
- In[]: math_B_mean
+ In[]: math_B_mean = sum(math_B) / len(math_B)
+ In[]: math_B_mean
\end{lstlisting}
\end{frame}
diff --git a/slides/basic_python/python.tex b/slides/basic_python/python.tex
index 19be639..446d38e 100644
--- a/slides/basic_python/python.tex
+++ b/slides/basic_python/python.tex
@@ -47,10 +47,10 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\tableofcontents
\end{frame}
-\include{slides/intro}
-\include{slides/strings_loops_lists}
-\include{slides/io_files_parsing}
-\include{slides/func}
-\include{slides/tuples_dicts_sets}
+\include{intro}
+\include{strings_loops_lists}
+\include{io_files_parsing}
+\include{func}
+\include{tuples_dicts_sets}
\end{document}
diff --git a/slides/basic_python/strings_loops_lists.tex b/slides/basic_python/strings_loops_lists.tex
index 26d7b54..1e5d05f 100644
--- a/slides/basic_python/strings_loops_lists.tex
+++ b/slides/basic_python/strings_loops_lists.tex
@@ -9,7 +9,7 @@
\end{itemize}
\begin{lstlisting}
In[]: 'This is a string'
- In[]: "This is a string too'
+ In[]: "This is a string too"
In[]: '''This is a string as well'''
In[]: """This is also a string"""
In[]: '' # empty string
@@ -72,7 +72,7 @@
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}
+ \emph{sat, Sat, SAT}
\end{block}
\begin{itemize}
\item Get the first 3 characters of the string
@@ -84,7 +84,7 @@
\begin{frame}[fragile]
\frametitle{Slicing}
\begin{lstlisting}
- In[]: q = "Hello World"
+ In[]: q = "Hello World"
In[]: q[0:3]
In[]: q[:3]
In[]: q[3:]
@@ -143,13 +143,13 @@
\item Possibly, each string separated by a common token
\end{itemize}
\begin{lstlisting}
- In[]: email_list = ["info@fossee.in",
+ In[]: email_list = ["info@fossee.in",
"enquiries@fossee.in",
"help@fossee.in"]
\end{lstlisting}
\begin{lstlisting}
- In[]: '; '.join(email_list)
- In[]: ', '.join(email_list)
+ In[]: '; '.join(email_list)
+ In[]: ', '.join(email_list)
\end{lstlisting}
\end{frame}
@@ -158,11 +158,11 @@
\begin{frame}[fragile]
\frametitle{\texttt{if-else} block}
\begin{lstlisting}
- In[]: a = 5
- In[]: if a % 2 == 0:
- ....: print "Even"
- ....: else:
- ....: print "Odd"
+ In[]: a = 5
+ In[]: if a % 2 == 0:
+ ....: print "Even"
+ ....: else:
+ ....: print "Odd"
\end{lstlisting}
\begin{itemize}
\item A code block -- \texttt{:} and indentation
@@ -189,12 +189,12 @@
\begin{frame}[fragile]
\frametitle{\texttt{else} is optional}
\begin{lstlisting}
- In[]: if user == 'admin':
- ....: admin_Operations()
- ....: elif user == 'moderator':
- ....: moderator_operations()
- ....: elif user == 'client':
- ....: customer_operations()
+ In[]: 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
@@ -242,11 +242,11 @@
\texttt{while}
\end{itemize}
\begin{lstlisting}
- In[]: i = 1
+ In[]: i = 1
- In[]: while i<10:
- ....: print i*i
- ....: i += 2
+ In[]: while i<10:
+ ....: print i*i
+ ....: i += 2
\end{lstlisting}
\begin{itemize}
\item The loops runs as long as the condition is \texttt{True}
@@ -260,18 +260,18 @@
\texttt{for}
\end{itemize}
\begin{lstlisting}
- In[]: for n in [1, 2, 3]:
- ....: print n
+ In[]: 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}
- In[]: for n in [1, 3, 5, 7, 9]:
- ....: print n*n
+ In[]: for n in [1, 3, 5, 7, 9]:
+ ....: print n*n
- In[]: for n in range(1, 10, 2):
- ....: print n*n
+ In[]: for n in range(1, 10, 2):
+ ....: print n*n
\end{lstlisting}
\begin{itemize}
\item \alert{range([start,] stop[, step])}
@@ -288,13 +288,13 @@
\texttt{break}
\end{itemize}
\begin{lstlisting}
- In[]: i = 1
+ In[]: i = 1
- In[]: while True:
- ....: print i*i
- ....: i += 2
- ....: if i>10:
- ....: break
+ In[]: while True:
+ ....: print i*i
+ ....: i += 2
+ ....: if i>10:
+ ....: break
\end{lstlisting}
\end{frame}
@@ -306,13 +306,31 @@
\item Squares of all odd numbers below 10, not multiples of 3
\end{itemize}
\begin{lstlisting}
- In[]: for n in range(1, 10, 2):
- ....: if n%3 == 0:
- ....: continue
- ....: print n*n
+ In[]: for n in range(1, 10, 2):
+ ....: if n%3 == 0:
+ ....: continue
+ ....: print n*n
\end{lstlisting}
\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}
+
\section{Lists}
@@ -333,10 +351,10 @@
\begin{frame}[fragile]
\frametitle{Accessing Elements}
\begin{lstlisting}
- In[]: print p[0], p[1], p[3]
+ In[]: print p[0], p[1], p[3]
- In[]: print p[-1], p[-2], p[-4]
- In[]: print p[10]
+ In[]: print p[-1], p[-2], p[-4]
+ In[]: print p[10]
\end{lstlisting}
\begin{itemize}
\item Indexing starts from 0
@@ -348,11 +366,11 @@
\begin{frame}[fragile]
\frametitle{Accessing Elements \& length}
\begin{lstlisting}
- In[]: print p[0], p[1], p[3]
+ In[]: print p[0], p[1], p[3]
In[]: print p[-1], p[-2], p[-4]
In[]: print len(p)
- In[]: print p[10]
+ In[]: print p[10]
\end{lstlisting}
\begin{itemize}
\item Indexing starts from 0
@@ -368,9 +386,9 @@
\item The append method adds elements to the end of the list
\end{itemize}
\begin{lstlisting}
- In[]: p.append('onemore')
- In[]: p
- In[]: p.append([1, 6])
+ In[]: p.append('onemore')
+ In[]: p
+ In[]: p.append([1, 6])
In[]: p
\end{lstlisting}
\begin{itemize}
@@ -390,10 +408,10 @@
\begin{frame}[fragile]
\frametitle{Concatenating lists}
\begin{lstlisting}
- In[]: a = [1, 2, 3, 4]
- In[]: b = [4, 5, 6, 7]
- In[]: a + b
- In[]: print a+b, a, b
+ In[]: a = [1, 2, 3, 4]
+ In[]: b = [4, 5, 6, 7]
+ In[]: a + b
+ In[]: print a+b, a, b
\end{lstlisting}
\begin{itemize}
\item A new list is returned; None of the original lists change
@@ -407,13 +425,13 @@
\begin{frame}[fragile]
\frametitle{Slicing \& Striding}
\begin{lstlisting}
- In[]: primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
- In[]: primes[4:8]
- In[]: primes[:4]
+ In[]: primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
+ In[]: primes[4:8]
+ In[]: primes[:4]
- In[]: num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
- In[]: num[1:10:2]
- In[]: num[:10]
+ In[]: num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
+ In[]: num[1:10:2]
+ In[]: num[:10]
In[]: num[10:]
In[]: num[::2]
In[]: num[::-1]
@@ -423,35 +441,35 @@
\begin{frame}[fragile]
\frametitle{Sorting}
\begin{lstlisting}
- In[]: a = [5, 1, 6, 7, 7, 10]
- In[]: a.sort()
- In[]: a
+ In[]: a = [5, 1, 6, 7, 7, 10]
+ In[]: a.sort()
+ In[]: 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}
- In[]: a = [5, 1, 6, 7, 7, 10]
- In[]: sorted(a)
- In[]: a
+ In[]: a = [5, 1, 6, 7, 7, 10]
+ In[]: sorted(a)
+ In[]: a
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Reversing}
\begin{lstlisting}
- In[]: a = [5, 1, 6, 7, 7, 10]
- In[]: a.reverse()
- In[]: a
+ In[]: a = [5, 1, 6, 7, 7, 10]
+ In[]: a.reverse()
+ In[]: 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}
- In[]: a = [5, 1, 6, 7, 7, 10]
- In[]: a[::-1]
- In[]: a
+ In[]: a = [5, 1, 6, 7, 7, 10]
+ In[]: a[::-1]
+ In[]: a
\end{lstlisting}
\end{frame}
diff --git a/slides/basic_python/tmp.tex b/slides/basic_python/tmp.tex
deleted file mode 100644
index 8b13789..0000000
--- a/slides/basic_python/tmp.tex
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/slides/basic_python/tuples_dicts_sets.tex b/slides/basic_python/tuples_dicts_sets.tex
index b09fd99..832a36c 100644
--- a/slides/basic_python/tuples_dicts_sets.tex
+++ b/slides/basic_python/tuples_dicts_sets.tex
@@ -3,15 +3,15 @@
\begin{frame}[fragile]
\frametitle{Tuples -- Initialization}
\begin{lstlisting}
- In[]: t = (1, 2.5, "hello", -4, "world", 1.24, 5)
- In[]: t
+ In[]: t = (1, 2.5, "hello", -4, "world", 1.24, 5)
+ In[]: t
\end{lstlisting}
\begin{itemize}
\item It is not always necessary to use parenthesis
\end{itemize}
\begin{lstlisting}
- In[]: a = 1, 2, 3
- In[]: b = 1,
+ In[]: a = 1, 2, 3
+ In[]: b = 1,
\end{lstlisting}
\end{frame}
@@ -30,26 +30,26 @@
\begin{frame}[fragile]
\frametitle{Swapping values}
\begin{lstlisting}
- In[]: a = 5
- In[]: b = 7
+ In[]: a = 5
+ In[]: b = 7
- In[]: temp = a
- In[]: a = b
- In[]: b = temp
+ In[]: temp = a
+ In[]: a = b
+ In[]: b = temp
\end{lstlisting}
\begin{itemize}
\item Here's the Pythonic way of doing it
\end{itemize}
\begin{lstlisting}
- In[]: a, b = b, a
+ In[]: a, b = b, a
\end{lstlisting}
\begin{itemize}
\item The variables can be of different data-types
\end{itemize}
\begin{lstlisting}
- In[]: a = 2.5
- In[]: b = "hello"
- In[]: a, b = b, a
+ In[]: a = 2.5
+ In[]: b = "hello"
+ In[]: a, b = b, a
\end{lstlisting}
\end{frame}
@@ -64,7 +64,7 @@
\item Tuple packing and unpacking, when swapping
\end{itemize}
\begin{lstlisting}
- In[]: a, b = b, a
+ In[]: a, b = b, a
\end{lstlisting}
\end{frame}
@@ -73,14 +73,14 @@
\begin{frame}[fragile]
\frametitle{Creating Dictionaries}
\begin{lstlisting}
- In[]: mt_dict = {}
+ In[]: mt_dict = {}
- In[]: extensions = {'jpg' : 'JPEG Image',
+ In[]: extensions = {'jpg' : 'JPEG Image',
'py' : 'Python script',
'html' : 'Html document',
'pdf' : 'Portable Document Format'}
- In[]: extensions
+ In[]: extensions
\end{lstlisting}
\begin{itemize}
\item Key-Value pairs
@@ -91,13 +91,13 @@
\begin{frame}[fragile]
\frametitle{Accessing Elements}
\begin{lstlisting}
- In[]: print extensions['jpg']
+ In[]: print extensions['jpg']
\end{lstlisting}
\begin{itemize}
\item Values can be accessed using keys
\end{itemize}
\begin{lstlisting}
- In[]: print extensions['zip']
+ In[]: print extensions['zip']
\end{lstlisting}
\begin{itemize}
\item Values of non-existent keys cannot, obviously, be accessed
@@ -163,9 +163,9 @@
\begin{frame}[fragile]
\frametitle{Creating Sets}
\begin{lstlisting}
- In[]: a_list = [1, 2, 1, 4, 5, 6, 2]
- In[]: a = set(a_list)
- In[]: a
+ In[]: a_list = [1, 2, 1, 4, 5, 6, 2]
+ In[]: a = set(a_list)
+ In[]: a
\end{lstlisting}
\begin{itemize}
\item Conceptually identical to the sets in mathematics
@@ -177,8 +177,8 @@
\begin{frame}[fragile]
\frametitle{Operations on Sets}
\begin{lstlisting}
- In[]: f10 = set([1, 2, 3, 5, 8])
- In[]: p10 = set([2, 3, 5, 7])
+ In[]: f10 = set([1, 2, 3, 5, 8])
+ In[]: p10 = set([2, 3, 5, 7])
\end{lstlisting}
\begin{itemize}
\item Mathematical operations performed on sets, can be performed
@@ -186,19 +186,19 @@
\begin{itemize}
\item Union
\begin{lstlisting}
- In[]: f10 | p10
+ In[]: f10 | p10
\end{lstlisting}
\item Intersection
\begin{lstlisting}
- In[]: f10 & p10
+ In[]: f10 & p10
\end{lstlisting}
\item Difference
\begin{lstlisting}
- In[]: f10 - p10
+ In[]: f10 - p10
\end{lstlisting}
\item Symmetric Difference
\begin{lstlisting}
- In[]: f10 ^ p10
+ In[]: f10 ^ p10
\end{lstlisting}
\end{itemize}
\end{frame}
@@ -208,12 +208,12 @@
\begin{itemize}
\item Proper Subset
\begin{lstlisting}
- In[]: b = set([1, 2])
- In[]: b < f10
+ In[]: b = set([1, 2])
+ In[]: b < f10
\end{lstlisting}
\item Subsets
\begin{lstlisting}
- In[]: f10 <= f10
+ In[]: f10 <= f10
\end{lstlisting}
\end{itemize}
\end{frame}
@@ -223,18 +223,18 @@
\begin{itemize}
\item Containership
\begin{lstlisting}
- In[]: 1 in f10
- In[]: 4 in f10
+ In[]: 1 in f10
+ In[]: 4 in f10
\end{lstlisting}
\item Iterating over elements
\begin{lstlisting}
- In[]: for i in f10:
+ In[]: for i in f10:
....: print i,
....:
\end{lstlisting}
\item Subsets
\begin{lstlisting}
- In[]: f10 <= f10
+ In[]: f10 <= f10
\end{lstlisting}
\end{itemize}
\end{frame}
@@ -246,13 +246,13 @@
all the duplicates
\end{block}
\begin{lstlisting}
- In[]: marks = [20, 23, 22, 23, 20, 21, 23]
- In[]: marks_set = set(marks)
- In[]: for mark in marks_set:
+ In[]: marks = [20, 23, 22, 23, 20, 21, 23]
+ In[]: marks_set = set(marks)
+ In[]: for mark in marks_set:
....: marks.remove(mark)
# left with only duplicates
- In[]: duplicates = set(marks)
+ In[]: duplicates = set(marks)
\end{lstlisting}
\end{frame}