# HG changeset patch # User Santosh G. Vattam # Date 1256298145 -19800 # Node ID 01f57cda252f9745b61cfa1890a14ee5960df528 # Parent 978108b0c02cc7493aabf7143d014acf41951d2b# Parent 55e8fc68835c2d400cd6864e1de17279b70c2c02 Manual merge of conflicting branches. diff -r 55e8fc68835c -r 01f57cda252f day1/session2.tex --- a/day1/session2.tex Fri Oct 23 16:20:31 2009 +0530 +++ b/day1/session2.tex Fri Oct 23 17:12:25 2009 +0530 @@ -211,6 +211,77 @@ \end{itemize} \end{frame} +\begin{frame}[fragile] +\frametitle{Plotting $L$ vs $T^2$} +\begin{lstlisting} +In []: TSq = [] + +In []: for t in T: + ....: TSq.append(t*t) + +In []: plot(L, TSq, '.') +Out[]: [] +\end{lstlisting} +\end{frame} + +\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{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} +\end{frame} + +\begin{frame}[fragile] + \frametitle{List: Slicing} + \typ{list[initial:final:step]} +\begin{lstlisting} +In []: lst[1:3] # A slice. +Out[]: [2, 3] + +In []: lst[1:-1] +Out[]: [2, 3] +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] + \frametitle{List methods} +\begin{lstlisting} +In []: lst.append([6,7]) +In []: lst +Out[]: [1, 2, 3, 4, 5, [6, 7]] +\end{lstlisting} +%\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] @@ -247,42 +318,4 @@ \inctime{5} \end{frame} -\section{Lists} - -\begin{frame}[fragile] - \frametitle{List creation and indexing} -\begin{lstlisting} -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} - \typ{list[initial:final:step]} -\begin{lstlisting} -In []: lst[1:3] # A slice. -Out[]: [2, 3] - -In []: lst[1:-1] -Out[]: [2, 3] -\end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \frametitle{List methods} -\begin{lstlisting} -In []: lst.append([6,7]) -In []: lst -Out[]: [1, 2, 3, 4, 5, [6, 7]] -\end{lstlisting} -\inctime{10} -\end{frame} - \end{document}