diff options
-rw-r--r-- | day1/session2.tex | 105 |
1 files changed, 69 insertions, 36 deletions
diff --git a/day1/session2.tex b/day1/session2.tex index 1a28cd1..b9654c1 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -211,60 +211,41 @@ In []: T = [0.6529, 0.8485, 1.0590, \end{itemize} \end{frame} - -\section{File Handling} \begin{frame}[fragile] - \frametitle{File and \kwrd{for}} +\frametitle{Plotting $L$ vs $T^2$} \begin{lstlisting} -In []: f = open('dummyfile') +In []: TSq = [] -In []: for line in f: - ...: print line - ...: -\end{lstlisting} -\inctime{5} -\end{frame} +In []: for t in T: + ....: TSq.append(t*t) -\section{Strings} -\begin{frame}{Strings} -Anything within ``quotes'' is a string! +In []: plot(L, TSq, '.') +Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>] +\end{lstlisting} \end{frame} -\begin{frame}[fragile]\frametitle{Strings and \typ{split()}} - \begin{lstlisting} -In []: a = 'hello world' - -In []: a.split() -Out[]: ['hello', 'world'] - \end{lstlisting} -Now try this: - \begin{lstlisting} -In []: b = 'KD, MCS, PC, SC, SV' - -In []: b.split(',') -Out[]: ['KD', 'MCS', 'PC', 'SC', 'SV'] - \end{lstlisting} -\inctime{5} +\begin{frame}{So what did we learn here??} + \begin{itemize} + \item lists + \item \alert{\kwrd{for}} + \end{itemize} \end{frame} \section{Lists} - \begin{frame}[fragile] - \frametitle{List creation and indexing} + \frametitle{How to create and use lists?} \begin{lstlisting} +In []: mtlist = [] #Empty List + In []: lst = [1,2,3,4] In []: lst[0]+lst[1]+lst[-1] Out[]: 7 \end{lstlisting} -\begin{itemize} - \item Indices start with ? - \item Negative indices indicate ? - \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{List: slices} + \frametitle{List: Slicing} \typ{list[initial:final:step]} \begin{lstlisting} In []: lst[1:3] # A slice. @@ -282,7 +263,59 @@ In []: lst.append([6,7]) In []: lst Out[]: [1, 2, 3, 4, 5, [6, 7]] \end{lstlisting} -\inctime{10} +%\inctime{10} +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{for}} +Used to iterate over lists\\ Let us look at another example. +\begin{lstlisting} +In []: lst = [1,2,3,4,5,6] +In []: for num in lst: + ....: print num, num*num + ....: +1 1 +2 4 +3 9 +4 16 +5 25 +6 36 +\end{lstlisting} +\end{frame} + +\section{File Handling} +\begin{frame}[fragile] + \frametitle{File and \kwrd{for}} +\begin{lstlisting} +In []: f = open('dummyfile') + +In []: for line in f: + ...: print line + ...: +\end{lstlisting} +\inctime{5} +\end{frame} + +\section{Strings} +\begin{frame}{Strings} +Anything within ``quotes'' is a string! +\end{frame} + +\begin{frame}[fragile]\frametitle{Strings and \typ{split()}} + \begin{lstlisting} +In []: a = 'hello world' + +In []: a.split() +Out[]: ['hello', 'world'] + \end{lstlisting} +Now try this: + \begin{lstlisting} +In []: b = 'KD, MCS, PC, SC, SV' + +In []: b.split(',') +Out[]: ['KD', 'MCS', 'PC', 'SC', 'SV'] + \end{lstlisting} +\inctime{5} \end{frame} \end{document} |