diff options
author | Jovina | 2011-05-11 15:15:49 +0530 |
---|---|---|
committer | Jovina | 2011-05-11 15:15:49 +0530 |
commit | e2049f9e6efffe0e5c2de469403d7872d42344ed (patch) | |
tree | 4f97d726fcadcd07a5b2875290d7c15d1adf97b8 /getting_started_with_lists | |
parent | 1940ed38ea2c2b7feb5a095857c526d17d3fd30a (diff) | |
download | st-scripts-e2049f9e6efffe0e5c2de469403d7872d42344ed.tar.gz st-scripts-e2049f9e6efffe0e5c2de469403d7872d42344ed.tar.bz2 st-scripts-e2049f9e6efffe0e5c2de469403d7872d42344ed.zip |
Modified the script ans slides for "Getting started with lists".
Diffstat (limited to 'getting_started_with_lists')
-rw-r--r-- | getting_started_with_lists/script.rst | 324 | ||||
-rw-r--r-- | getting_started_with_lists/slides.org | 85 | ||||
-rw-r--r-- | getting_started_with_lists/slides.tex | 131 |
3 files changed, 344 insertions, 196 deletions
diff --git a/getting_started_with_lists/script.rst b/getting_started_with_lists/script.rst index 5a084f9..e5fd5b5 100644 --- a/getting_started_with_lists/script.rst +++ b/getting_started_with_lists/script.rst @@ -25,218 +25,316 @@ Language Reviewer : Bhanukiran Checklist OK? : <12-11-2010, Anand, OK> [2010-10-05] -.. #[[Anoop: Slides contain only outline and summary Script ------ - {{{ Show the slide containing title }}} -Hello friends and welcome to the tutorial on getting started with -lists. +.. L1 - {{{ Show the slide containing the outline slide }}} +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and welcome to the tutorial on "Getting started with +lists". + +.. L2 + +{{{ Show slide with objectives }}} + +.. R2 In this tutorial we will be getting acquainted with a python data -structure called lists. We will learn :: +structure called lists. +At the end of this tutorial, you will be able to, - * How to create lists - * Structure of lists - * Access list elements - * Append elements to lists - * Delete elements from lists + 1. Create lists + #. Access list elements + #. Append elements to lists + #. Delete elements from lists -List is a compound data type, it can contain data of mutually -different datatypes. List is also a sequence data type, all the -elements are arranged in a given order. +.. R3 -.. #[[Anoop: "all the elements are in order and **there** order has a - meaning." - I guess something is wrong here, I am not able to - follow this.]] +List is a compound data type, it can contain data of mutually +different datatypes. List is also a sequence data type where all the +elements are arranged in a specific order. -We will first create an empty list with no elements. On your IPython -shell type :: +Start the ipython interpreter and first create an empty list with no elements. - empty = [] - type(empty) +.. L3 +:: + ipython + empty = [] + type(empty) +.. R4 + This is an empty list without any elements. -.. #[[Anoop: the document has to be continous, without any - subheadings, removing * Filled lists]] +Let us now see how to define a non-empty list. -Lets now see how to define a non-empty list. We do it as,:: +.. L4 +:: - nonempty = ['spam', 'eggs', 100, 1.234] + nonempty = ['spam', 'eggs', 100, 1.234] + +.. R5 Thus the simplest way of creating a list is typing out a sequence of comma-separated values (or items) between two square brackets. As we can see lists can contain different kinds of data. In the previous example 'spam' and 'eggs' are strings whereas 100 and 1.234 are -integer and float respectively. Thus we can put elements of different types in +integer and float respectively. Thus we can put elements of different datatypes in lists including lists itself. This property makes lists heterogeneous data structures. -.. #[[Anoop: the sentence "Thus list themselves can be one of the - element types possible in lists" is not clear, rephrase it.]] +Let us include a list within a list. + +.. L5 +:: -Example :: + listinlist=[[4,2,3,4],'and', 1, 2, 3, 4] - listinlist=[[4,2,3,4],'and', 1, 2, 3, 4] +.. R6 We access an element of a list using its corresponding index. Index of the first element of a list is 0. So for the list nonempty, nonempty[0] gives the first element, nonempty[1] the second element and so on and -nonempty[3] the last element. :: +nonempty[3] the last element. + +.. L6 +:: + + nonempty[0] + nonempty[1] + nonempty[3] + +.. L7 - nonempty[0] - nonempty[1] - nonempty[3] +{{{ Switch to the slide Question 1 }}} -Following is an exercise that you must do. +.. R7 -%% %% What happens when you do nonempty[-1]. +Pause the video here, try out the following exercise and resume the video. -Please, pause the video here. Do the exercise and then continue. +What happens when you do nonempty[-1]. -.. #[[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.]] +.. L8 + +{{{ Switch to the terminal }}} +:: + + nonempty[-1] + +.. R8 As you can see you get the last element which is 1.234. +.. L9 +:: + + nonempty[-2] + nonempty[-4] -In python negative indices are used to access elements from the end:: - - nonempty[-1] - nonempty[-2] - nonempty[-4] +.. R9 --1 gives the last element which is the 4th element , -2 second to last -and -4 gives the fourth from the last which, in this case, is the first element. +In python negative indices are used to access elements from the end. +-1 gives the last element which is the 4th element , -2 gives second element to last +and -4 gives the fourth from the last which, in this case, is the first element. -We can append elements to the end of a list using the method append. :: +.. R10 - nonempty.append('onemore') - nonempty - nonempty.append(6) - nonempty +We can also append elements to the end of a list using the method ``append``. + +.. L10 +:: + + nonempty.append('onemore') + nonempty + nonempty.append(6) + nonempty + +.. L11 + +{{{ Switch to slide Question 2 }}} + +.. R11 -Following are exercises that you must do. +Please, pause the video here. Do the exercise and then continue. -%% %% What is the syntax to get the element 'and' -in the list,listinlist ? +1. What is the syntax to get the element 'and' in the list,listinlist ? +2. How would you get 'and' using negative indices? +.. L12 -%% %% How would you get 'and' using negative indices? +{{{ Switch to slide Solution 2 }}} -Please, pause the video here. Do the exercise and then continue. +.. R12 The solution is on your screen +As we can see nonempty is appended with 'onemore' and 6 at the end. +.. R13 -As we can see nonempty is appended with 'onemore' and 6 at the end. +Let us move further.We can use ``len`` function to check the number of elements in the list. +Let us find out the length of the list 'nonempty'. -Using len function we can check the number of elements in the list -nonempty. In this case it is 6 :: +.. L13 +:: - len(nonempty) - + len(nonempty) +.. R14 Just like we can append elements to a list we can also remove them. -There are two ways of doing it. One is by using index. :: +There are two ways of doing it. One is by using index. - del(nonempty[1]) +.. L14 +:: + del(nonempty[1]) +.. R15 -deletes the element at index 1, i.e the second element of the -list, 'eggs'. The other way is removing element by content. Lets say -one wishes to delete 100 from nonempty list the syntax of the command -would be +The function ``del`` deletes the element at index 1, i.e the second element of the +list, 'eggs'. -.. #[[Anoop: let x = [1,2,1,3] - now x.remove(x[2]) - still x is [2,1,3] so that is not the way to remove - element by index, it removed first occurrence of 1(by - content) and not based on index, so make necessary - changes]] +The other way is removing element by content. Lets say +one wishes to delete 100 from nonempty list.For this, one could use the function +``remove``. +.. L15 :: nonempty.remove(100) -but what if there were two 100's. To check that lets do a small -experiment. :: +.. R16 + +But what if there were two 100's. To check that lets do a small +experiment. + +.. L16 +:: + + nonempty.append('spam') + nonempty + nonempty.remove('spam') + nonempty - nonempty.append('spam') - nonempty - nonempty.remove('spam') - nonempty +.. R17 -If we check now we will see that the first occurence 'spam' is removed -and therefore `remove` removes the first occurence of the element in the sequence +If we now check, we will see that the first occurence 'spam' is removed +and therefore the function `remove` removes the first occurence of the element in the sequence and leaves others untouched. -One should remember this that while del removes by index number, -`remove` removes on the basis of content being passed on. For instance -if :: - - k = [1,2,1,3] - del([k[2]) +One should remember this, that while ``del`` removes by index number, +`remove` removes on the basis of content being passed on.Let us take an example. -gives us [1,2,3]. :: +.. L17 - k.remove(x[2]) +.. L18 +:: + + k = [1,2,1,3] + del([k[2]) -will give us [2,1,3]. Since it deletes the first occurence of what is -returned by x[2] which is 1. +.. R18 +del gives us [1,2,3]. +.. L19 +:: + k.remove(x[2]) +.. R19 +remove will give us [2,1,3]. Since it deletes the first occurence of what is +returned by x[2] which is 1. +.. L20 -.. #[[Anoop: does it have two spams or two pythons?]] +{{{ Switch to the slide Question 3 }}} -.. #[[Anoop: there are no exercises/solved problems in this script, - add them]] +.. R20 -Following are exercises that you must do. +Pause the video here, try out the following exercise and resume the video. -%% %% Remove the third element from the list, listinlist. +1. Remove the third element from the list, listinlist. +2. Remove 'and' from the list, listinlist. -%% %% Remove 'and' from the list, listinlist. +.. L21 -Please, pause the video here. Do the exercise and then continue. +{{{ Switch to slide Solution 3 }}} +.. R21 +The solution is on your screen. + +.. L22 {{{Slide for Summary }}} +.. R22 + +This brings us to the end of this tutorial. +In this tutorial we learnt to, -In this tutorial we came across a sequence data type called lists. :: + 1. Create lists. + #. Access lists using their index numbers. + #. Append elements to list using the function ``append``. + #. Delete Element from lists by specifying the index number of the + element to be deleted in the ``del`` function. + #. Delete element from list by content using ``remove`` function. + #. Find out the list length using ``len`` function. - * We learned how to create lists. - * How to access lists. - * Append elements to list. - * Delete Element from list. - * And Checking list length. +.. L23 +{{Show self assessment questions slide}} + +.. R23 + +Here are some self assessment questions for you to solve + +1. How do you create an empty list? +2. Can you have a list inside a list ? +3. How would you access the end of a list without finding its length? + +.. L24 + +{{{solution of self assessment questions on slide}}} + +.. R24 + +And the answers, + +1. We create an empty list just by leaving the space inside the square brackets empty. +:: + + empty=[] + +2. Yes.List can contain all the other data types, including list. + Here is an example +:: + + list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there'] + +3. Using negative indices, we can access the list from the end using negative indices. + This is an example +:: + nonempty = ['spam', 'eggs', 100, 1.234] + nonempty[-1] -{{{ show Sponsored by Fossee Slide }}} +.. L25 -This tutorial was created as a part of FOSSEE project. +{{{ Show Thankyou Slide }}} -I hope you found this tutorial useful. +.. R25 -Thank You +Hope you have enjoyed and found it useful. +Thank you! -.. - * Author : Amit Sethi - * First Reviewer : - * Second Reviewer : Nishanth diff --git a/getting_started_with_lists/slides.org b/getting_started_with_lists/slides.org index f7cb690..d7213de 100644 --- a/getting_started_with_lists/slides.org +++ b/getting_started_with_lists/slides.org @@ -18,7 +18,7 @@ #+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, #+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} -#+TITLE: Getting started with Lists +#+TITLE: #+AUTHOR: FOSSEE #+DATE: 2010-09-14 Tue #+EMAIL: info@fossee.in @@ -30,41 +30,49 @@ #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc -* Outline - - How to create lists - - Structure of lists - - Access list elements - - Append elements to lists - - Deleting elements from lists +* + #+begin_latex +\begin{center} +\textcolor{blue}{Getting started with Lists} +\end{center} +\begin{center} +\includegraphics[scale=0.25]{../images/iitb-logo.png}\\ +Developed by FOSSEE Team, IIT-Bombay. \\ +Funded by National Mission on Education through ICT +MHRD, Govt. of India +\end{center} +#+end_latex +* Objectives + At the end of this tutorial, you will be able to, + - Create lists + - Access list elements + - Append elements to lists + - Delete elements from lists * Question 1 - What happens when you do nonempty[-1]. -* Solution 1 - - It gives the last element , 1.234 - -* Questions +* Question 2 - What is the syntax to get the element 'and' -in the list,listinlist ? - - + in the list,listinlist ? - How would you get 'and' using negative indices? -* Solutions +* Solution 2 + #+begin_src python listinlist[1] listinlist[-5] #+end_src python -* Questions +* Question 3 - Remove the third element from the list, listinlist. - Remove 'and' from the list, listinlist. -* Solutions +* Solution 3 #+begin_src python del(listinlist[2]) @@ -72,27 +80,36 @@ in the list,listinlist ? #+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! + In this tutorial, we have learnt to – + - Create lists. + - Access lists using their index numbers. + - Append elements to list using the function ``append``. + - Delete Element from lists by specifying the index number of the + element to be deleted in the ``del`` function. + - Delete element from list by content using ``remove`` function. + - Find out the list length using the ``len`` function. +* Evaluation + 1. How do you create an empty list? + 2. Can you have a list inside a list ? + 3. How would you access the end of a list without finding its length? +* Solutions + 1. empty=[] + 2. Yes\\ + list\_in\_list=[2.3,[2,4,6],'string,'all datatypes can be there'] + 3. Using negative indices\\ + nonempty = ['spam', 'eggs', 100, 1.234]\\ + nonempty[-1] +* Acknowledgement #+begin_latex - \begin{block}{} + \begin{block}{} \begin{center} - This spoken tutorial has been produced by the - \textcolor{blue}{FOSSEE} team, which is funded by the + \textcolor{blue}{\Large THANK YOU!} \end{center} + \end{block} +\begin{block}{} \begin{center} - \textcolor{blue}{National Mission on Education through \\ - Information \& Communication Technology \\ - MHRD, Govt. of India}. + For more Information, visit our website\\ + \url{http://fossee.in/} \end{center} \end{block} #+end_latex diff --git a/getting_started_with_lists/slides.tex b/getting_started_with_lists/slides.tex index 42c6f0a..d1c81e1 100644 --- a/getting_started_with_lists/slides.tex +++ b/getting_started_with_lists/slides.tex @@ -1,6 +1,6 @@ -% Created 2010-11-10 Wed 12:22 +% Created 2011-05-11 Wed 15:13 \documentclass[presentation]{beamer} -\usepackage[latin1]{inputenc} +\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{fixltx2e} \usepackage{graphicx} @@ -8,7 +8,6 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} -\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -24,14 +23,14 @@ commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, showstringspaces=false, keywordstyle=\color{blue}\bfseries} \providecommand{\alert}[1]{\textbf{#1}} -\title{Getting started with Lists} +\title{} \author{FOSSEE} \date{2010-09-14 Tue} \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} -\maketitle + @@ -43,107 +42,141 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \begin{frame} -\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} +\begin{center} +\textcolor{blue}{Getting started with Lists} +\end{center} +\begin{center} +\includegraphics[scale=0.25]{../images/iitb-logo.png}\\ +Developed by FOSSEE Team, IIT-Bombay. \\ +Funded by National Mission on Education through ICT + +MHRD, Govt. of India +\end{center} \end{frame} \begin{frame} -\frametitle{Question 1} +\frametitle{Objectives} \label{sec-2} + At the end of this tutorial, you will be able to, + \begin{itemize} -\item What happens when you do nonempty[-1]. +\item Create lists +\item Access list elements +\item Append elements to lists +\item Delete elements from lists \end{itemize} \end{frame} \begin{frame} -\frametitle{Solution 1} +\frametitle{Question 1} \label{sec-3} + \begin{itemize} -\item It gives the last element , 1.234 +\item What happens when you do nonempty[-1]. \end{itemize} \end{frame} \begin{frame} -\frametitle{Questions} +\frametitle{Question 2} \label{sec-4} -\begin{itemize} -\item What is the syntax to get the element `and' -\end{itemize} - -in the list,listinlist ? - \begin{itemize} +\item What is the syntax to get the element `and' + in the list,listinlist ? \item How would you get `and' using negative indices? \end{itemize} \end{frame} \begin{frame}[fragile] -\frametitle{Solutions} +\frametitle{Solution 2} \label{sec-5} -\begin{verbatim} + +\lstset{language=Python} +\begin{lstlisting} listinlist[1] listinlist[-5] -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} -\frametitle{Questions} +\frametitle{Question 3} \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} +\frametitle{Solution 3} \label{sec-7} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} del(listinlist[2]) listinlist.remove('and') -\end{verbatim} +\end{lstlisting} \end{frame} -\begin{frame}[fragile] +\begin{frame} \frametitle{Summary} \label{sec-8} -\begin{verbatim} + In this tutorial, we have learnt to – -l=[1,2,3,4] -l[-1] -l.append(5) -del(l[2]) -l.remove(2) -len(l) -\end{verbatim} +\begin{itemize} +\item Create lists. +\item Access lists using their index numbers. +\item Append elements to list using the function ``append``. +\item Delete Element from lists by specifying the index number of the + element to be deleted in the ``del`` function. +\item Delete element from list by content using ``remove`` function. +\item Find out the list length using the ``len`` function. +\end{itemize} \end{frame} \begin{frame} -\frametitle{Thank you!} +\frametitle{Evaluation} \label{sec-9} - \begin{block}{} + +\begin{enumerate} +\item How do you create an empty list? +\item Can you have a list inside a list ? +\item How would you access the end of a list without finding its length? +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Solutions} +\label{sec-10} + + +\begin{enumerate} +\item empty=[] +\item Yes\\ +list\_in\_list=[2.3,[2,4,6],'string,'all datatypes can be there'] +\item Using negative indices\\ +nonempty = ['spam', `eggs', 100, 1.234]\\ + nonempty[-1] +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Acknowledgement} +\label{sec-11} + + \begin{block}{} \begin{center} - This spoken tutorial has been produced by the - \textcolor{blue}{FOSSEE} team, which is funded by the + \textcolor{blue}{\Large THANK YOU!} \end{center} + \end{block} +\begin{block}{} \begin{center} - \textcolor{blue}{National Mission on Education through \\ - Information \& Communication Technology \\ - MHRD, Govt. of India}. + For more Information, visit our website\\ + \url{http://fossee.in/} \end{center} \end{block} \end{frame} -\end{document} +\end{document}
\ No newline at end of file |