diff options
Diffstat (limited to 'getting-started-with-lists')
-rw-r--r-- | getting-started-with-lists/script.rst | 49 | ||||
-rw-r--r-- | getting-started-with-lists/slides.org | 89 | ||||
-rw-r--r-- | getting-started-with-lists/slides.tex | 125 |
3 files changed, 224 insertions, 39 deletions
diff --git a/getting-started-with-lists/script.rst b/getting-started-with-lists/script.rst index 37d4ad7..61271e4 100644 --- a/getting-started-with-lists/script.rst +++ b/getting-started-with-lists/script.rst @@ -46,7 +46,7 @@ structure called lists. We will learn :: List is a compound data type, it can contain data of other data types. List is also a sequence data type, all the elements are in -order and there order has a meaning. +order and the order has a meaning. .. #[[Anoop: "all the elements are in order and **there** order has a meaning." - I guess something is wrong here, I am not able to @@ -75,15 +75,14 @@ All the list items need not be of the same data type. As we can see lists can contain different kinds of data. In the previous example 'spam' and 'eggs' are strings and 100 and 1.234 are integer and float. Thus we can put elements of heterogenous types in -lists. Thus list themselves can be one of the element types possible -in lists. Thus lists can also contain other lists. +lists including list itself. .. #[[Anoop: the sentence "Thus list themselves can be one of the element types possible in lists" is not clear, rephrase it.]] Example :: - list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4] + listinlist=[[4,2,3,4],'and', 1, 2, 3, 4] We access list elements using the index. The index begins from 0. So for list nonempty, nonempty[0] gives the first element, nonempty[1] @@ -93,11 +92,20 @@ the second element and so on and nonempty[3] the last element. :: nonempty[1] nonempty[3] +Following is an exercise that you must do. + +%% %% What happens when you do nonempty[-1]. + +Please, pause the video here. Do the exercise and then continue. + .. #[[Anoop: was negative indices introduced earlier, if not may be we can ask them to try out nonempty[-1] and see what happens and then tell that it gives the last element in the list.]] -We can also access the elememts from the end using negative indices :: +As you can see you get the last element which is 1.234. + + +In python negative indices are used to access elements from the end:: nonempty[-1] nonempty[-2] @@ -113,6 +121,19 @@ We can append elements to the end of a list using append command. :: nonempty.append(6) nonempty +Following are exercises that you must do. + +%% %% What is the syntax to get the element 'and' +in the list,listinlist ? + + +%% %% How would you get 'and' using negative indices? + +Please, pause the video here. Do the exercise and then continue. + +The solution is on your screen + + As we can see non empty appends 'onemore' and 6 at the end. Using len function we can check the number of elements in the list @@ -148,20 +169,34 @@ should be but what if there were two 100's. To check that lets do a small experiment. :: - nonempty.append('python') + nonempty.append('spam') nonempty - nonempty.remove('python') + nonempty.remove('spam') nonempty If we check now we will see that the first occurence 'spam' is removed thus remove removes the first occurence of the element in the sequence and leaves others untouched. + + + + .. #[[Anoop: does it have two spams or two pythons?]] .. #[[Anoop: there are no exercises/solved problems in this script, add them]] +Following are exercises that you must do. + +%% %% Remove the third element from the list, listinlist. + +%% %% Remove 'and' from the list, listinlist. + +Please, pause the video here. Do the exercise and then continue. + + + {{{Slide for Summary }}} diff --git a/getting-started-with-lists/slides.org b/getting-started-with-lists/slides.org index 34bb65a..f7cb690 100644 --- a/getting-started-with-lists/slides.org +++ b/getting-started-with-lists/slides.org @@ -2,34 +2,99 @@ #+LaTeX_CLASS_OPTIONS: [presentation] #+BEAMER_FRAME_LEVEL: 1 -#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC -#+OPTIONS: H:5 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} #+TITLE: Getting started with Lists #+AUTHOR: FOSSEE #+DATE: 2010-09-14 Tue #+EMAIL: info@fossee.in -# \author[FOSSEE] {FOSSEE} +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc -# \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -# \date{} -* Tutorial Plan -** How to create lists -** Structure of lists -** Access list elements -** Append elements to lists -** Deleting elements from lists +* Outline + - How to create lists + - Structure of lists + - Access list elements + - Append elements to lists + - Deleting elements from lists -* Summary +* Question 1 + - What happens when you do nonempty[-1]. + +* Solution 1 + - It gives the last element , 1.234 + +* Questions + - What is the syntax to get the element 'and' +in the list,listinlist ? + + - How would you get 'and' using negative indices? + +* Solutions +#+begin_src python + + listinlist[1] + listinlist[-5] + +#+end_src python +* Questions + + - Remove the third element from the list, listinlist. + + - Remove 'and' from the list, listinlist. + +* Solutions +#+begin_src python + + del(listinlist[2]) + listinlist.remove('and') + +#+end_src python +* Summary +#+begin_src python + l=[1,2,3,4] l[-1] l.append(5) del(l[2]) + l.remove(2) len(l) +#+end_src python +* Thank you! +#+begin_latex + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +#+end_latex + + diff --git a/getting-started-with-lists/slides.tex b/getting-started-with-lists/slides.tex index 0465d54..42c6f0a 100644 --- a/getting-started-with-lists/slides.tex +++ b/getting-started-with-lists/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-11-09 Tue 17:41 +% Created 2010-11-10 Wed 12:22 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -16,13 +16,19 @@ \usepackage{amssymb} \usepackage{hyperref} \tolerance=1000 +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} \providecommand{\alert}[1]{\textbf{#1}} \title{Getting started with Lists} \author{FOSSEE} \date{2010-09-14 Tue} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} \maketitle @@ -32,33 +38,112 @@ + + + + \begin{frame} -\frametitle{Tutorial Plan} +\frametitle{Outline} \label{sec-1} + +\begin{itemize} +\item How to create lists +\item Structure of lists +\item Access list elements +\item Append elements to lists +\item Deleting elements from lists +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-2} + \begin{itemize} +\item What happens when you do nonempty[-1]. +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Solution 1} +\label{sec-3} -\item How to create lists\\ -\label{sec-1_1}% -\item Structure of lists\\ -\label{sec-1_2}% -\item Access list elements\\ -\label{sec-1_3}% -\item Append elements to lists\\ -\label{sec-1_4}% -\item Deleting elements from lists\\ -\label{sec-1_5}% -\end{itemize} % ends low level +\begin{itemize} +\item It gives the last element , 1.234 +\end{itemize} \end{frame} \begin{frame} +\frametitle{Questions} +\label{sec-4} + +\begin{itemize} +\item What is the syntax to get the element `and' +\end{itemize} + +in the list,listinlist ? + + +\begin{itemize} +\item How would you get `and' using negative indices? +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solutions} +\label{sec-5} + +\begin{verbatim} + +listinlist[1] +listinlist[-5] +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Questions} +\label{sec-6} + + +\begin{itemize} +\item Remove the third element from the list, listinlist. +\item Remove `and' from the list, listinlist. +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solutions} +\label{sec-7} + +\begin{verbatim} + +del(listinlist[2]) +listinlist.remove('and') +\end{verbatim} +\end{frame} +\begin{frame}[fragile] \frametitle{Summary} -\label{sec-2} +\label{sec-8} + +\begin{verbatim} +l=[1,2,3,4] +l[-1] +l.append(5) +del(l[2]) +l.remove(2) +len(l) +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-9} - l=[1,2,3,4] - l[-1] - l.append(5) - del(l\footnote{FOOTNOTE DEFINITION NOT FOUND: 2 }) - len(l) + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} \end{frame} \end{document} |