day1/session2.tex
changeset 160 058fad7c7d1d
parent 159 01f57cda252f
child 161 ff22fae4fde5
equal deleted inserted replaced
159:01f57cda252f 160:058fad7c7d1d
   244 \end{lstlisting}
   244 \end{lstlisting}
   245 \end{frame}
   245 \end{frame}
   246 
   246 
   247 \begin{frame}[fragile]
   247 \begin{frame}[fragile]
   248   \frametitle{List: Slicing}
   248   \frametitle{List: Slicing}
   249   \typ{list[initial:final:step]}
   249 list[initial:final:step]
   250 \begin{lstlisting}
   250 \begin{lstlisting}
   251 In []: lst[1:3]  # A slice.
   251 In []: lst[1:3]  # A slice.
   252 Out[]: [2, 3]
   252 Out[]: [2, 3]
   253 
   253 
   254 In []: lst[1:-1]
   254 In []: lst[1:-1]
   257 \end{frame}
   257 \end{frame}
   258 
   258 
   259 \begin{frame}[fragile]
   259 \begin{frame}[fragile]
   260   \frametitle{List methods}
   260   \frametitle{List methods}
   261 \begin{lstlisting}
   261 \begin{lstlisting}
   262 In []: lst.append([6,7])
   262 In []: lst.append(6)
   263 In []: lst
   263 In []: lst
   264 Out[]: [1, 2, 3, 4, 5, [6, 7]]
   264 Out[]: [1, 2, 3, 4, 5, 6]
   265 \end{lstlisting}
   265 \end{lstlisting}
   266 %\inctime{10}
   266 %\inctime{10}
   267 \end{frame}
   267 \end{frame}
   268 
   268 
   269 \begin{frame}[fragile]
   269 \begin{frame}[fragile]
   270 \frametitle{\typ{for}}
   270 \frametitle{\texttt{for}}
   271 Used to iterate over lists\\ Let us look at another example.
   271 Used to iterate over lists\\ Let us look at another example.
   272 \begin{lstlisting}
   272 \begin{lstlisting}
   273 In []: lst = [1,2,3,4,5,6]
   273 In []: lst = [1,2,3,4,5,6]
   274 In []: for num in lst:
   274 In []: for num in lst:
   275  ....:     print num, num*num
   275  ....:     print num, num*num