summaryrefslogtreecommitdiff
path: root/getting_started_with_lists
diff options
context:
space:
mode:
authorPuneeth Chaganti2010-12-01 16:51:35 +0530
committerPuneeth Chaganti2010-12-01 16:51:35 +0530
commitf3a34dfb4e879f3eb7274704f44546aac4add88f (patch)
tree1cb0a8cc5dbd5ee2b374350915ed2addfa0fb447 /getting_started_with_lists
parent347866ed0d29db61ee062563b1e1616cfb85588c (diff)
downloadst-scripts-f3a34dfb4e879f3eb7274704f44546aac4add88f.tar.gz
st-scripts-f3a34dfb4e879f3eb7274704f44546aac4add88f.tar.bz2
st-scripts-f3a34dfb4e879f3eb7274704f44546aac4add88f.zip
Renamed all LOs to match with their names in progress.org.
Diffstat (limited to 'getting_started_with_lists')
-rw-r--r--getting_started_with_lists/quickref.tex19
-rw-r--r--getting_started_with_lists/script.rst242
-rw-r--r--getting_started_with_lists/script.rst.orig224
-rw-r--r--getting_started_with_lists/slides.org100
-rw-r--r--getting_started_with_lists/slides.tex149
5 files changed, 734 insertions, 0 deletions
diff --git a/getting_started_with_lists/quickref.tex b/getting_started_with_lists/quickref.tex
new file mode 100644
index 0000000..bfe61ef
--- /dev/null
+++ b/getting_started_with_lists/quickref.tex
@@ -0,0 +1,19 @@
+Creating an list\\
+{\ex \lstinline| empty=[]|}
+
+Create a filled list\\
+{\ex \lstinline| nonempty = ['spam', 'eggs', 100, 1.234] |}
+
+Accessing a list\\
+{\ex \lstinline| nonempty[0] |}
+{\ex \lstinline| nonempty[-1] |}
+
+Length of a list\\
+{\ex \lstinline| len(nonempty) |}
+
+Append an element to a list\\
+{\ex \lstinline| nonempty.append('python') |}
+
+Remove elements of a list\\
+{\ex \lstinline| del(nonempty[1] |}
+{\ex \lstinline| nonempty.remove(100) |}
diff --git a/getting_started_with_lists/script.rst b/getting_started_with_lists/script.rst
new file mode 100644
index 0000000..5a084f9
--- /dev/null
+++ b/getting_started_with_lists/script.rst
@@ -0,0 +1,242 @@
+.. Objectives
+.. ----------
+
+.. By the end of this tutorial, you will be able to
+
+.. Create Lists.
+.. Access List elements.
+.. Append elemets to list
+.. Delete list elemets
+
+.. 1. getting started with ipython
+
+
+
+.. Prerequisites
+.. -------------
+
+.. 1. getting started with strings
+.. #. getting started with lists
+.. #. basic datatypes
+
+.. Author : Amit
+ Internal Reviewer : Anoop Jacob Thomas <anoop@fossee.in>
+ External Reviewer :
+ 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.
+
+ {{{ Show the slide containing the outline slide }}}
+
+In this tutorial we will be getting acquainted with a python data
+structure called lists. We will learn ::
+
+ * How to create lists
+ * Structure of 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.
+
+.. #[[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.]]
+
+We will first create an empty list with no elements. On your IPython
+shell type ::
+
+ empty = []
+ type(empty)
+
+
+This is an empty list without any elements.
+
+.. #[[Anoop: the document has to be continous, without any
+ subheadings, removing * Filled lists]]
+
+Lets now see how to define a non-empty list. We do it as,::
+
+ nonempty = ['spam', 'eggs', 100, 1.234]
+
+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
+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.]]
+
+Example ::
+
+ listinlist=[[4,2,3,4],'and', 1, 2, 3, 4]
+
+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[0]
+ 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.]]
+
+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]
+ nonempty[-4]
+
+-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.
+
+We can append elements to the end of a list using the method append. ::
+
+ nonempty.append('onemore')
+ nonempty
+ 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 nonempty is appended with 'onemore' and 6 at the end.
+
+Using len function we can check the number of elements in the list
+nonempty. In this case it is 6 ::
+
+ len(nonempty)
+
+
+
+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. ::
+
+ del(nonempty[1])
+
+
+
+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
+
+.. #[[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]]
+
+::
+
+ nonempty.remove(100)
+
+but what if there were two 100's. To check that lets do a small
+experiment. ::
+
+ nonempty.append('spam')
+ nonempty
+ nonempty.remove('spam')
+ nonempty
+
+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
+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])
+
+gives us [1,2,3]. ::
+
+ k.remove(x[2])
+
+will give us [2,1,3]. Since it deletes the first occurence of what is
+returned by x[2] which is 1.
+
+
+
+
+
+
+
+.. #[[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 }}}
+
+
+In this tutorial we came across a sequence data type called lists. ::
+
+ * We learned how to create lists.
+ * How to access lists.
+ * Append elements to list.
+ * Delete Element from list.
+ * And Checking list length.
+
+
+
+{{{ show Sponsored by Fossee Slide }}}
+
+This tutorial was created as a part of FOSSEE project.
+
+I hope you found this tutorial useful.
+
+Thank You
+
+..
+ * Author : Amit Sethi
+ * First Reviewer :
+ * Second Reviewer : Nishanth
diff --git a/getting_started_with_lists/script.rst.orig b/getting_started_with_lists/script.rst.orig
new file mode 100644
index 0000000..3f068eb
--- /dev/null
+++ b/getting_started_with_lists/script.rst.orig
@@ -0,0 +1,224 @@
+.. Objectives
+.. ----------
+
+.. By the end of this tutorial, you will be able to
+
+.. Create Lists.
+.. Access List elements.
+.. Append elemets to list
+.. Delete list elemets
+
+.. 1. getting started with ipython
+
+
+
+.. Prerequisites
+.. -------------
+
+.. 1. getting started with strings
+.. #. getting started with lists
+.. #. basic datatypes
+
+.. Author : Amit
+ Internal Reviewer : Anoop Jacob Thomas <anoop@fossee.in>
+ External Reviewer :
+ Checklist OK? : <put date stamp here, if 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.
+
+ {{{ Show the slide containing the outline slide }}}
+
+In this tutorial we will be getting acquainted with a python data
+structure called lists. We will learn ::
+
+ * How to create lists
+ * Structure of lists
+ * Access list elements
+ * Append elements to lists
+ * Delete elements from lists
+
+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 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
+ follow this.]]
+
+We will first create an empty list with no elements. On your IPython
+shell type ::
+
+ empty = []
+ type(empty)
+
+
+This is an empty list without any elements.
+
+.. #[[Anoop: the document has to be continous, without any
+ subheadings, removing * Filled lists]]
+
+Lets now see how to define a non-empty list. We do it as,::
+
+ nonempty = ['spam', 'eggs', 100, 1.234]
+
+Thus the simplest way of creating a list is typing out a sequence
+of comma-separated values (items) between square brackets.
+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 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 ::
+
+ 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]
+the second element and so on and nonempty[3] the last element. ::
+
+ nonempty[0]
+ 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.]]
+
+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]
+ nonempty[-4]
+
+-1 gives the last element which is the 4th element , -2 second to last
+and -4 gives the fourth from last element which is first element.
+
+We can append elements to the end of a list using append command. ::
+
+ nonempty.append('onemore')
+ nonempty
+ 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
+nonempty. In this case it 6 ::
+
+ len(nonempty)
+
+
+
+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. ::
+
+ del(nonempty[1])
+
+
+
+deletes the element at index 1, 'eggs' which is the second element of
+the list. The other way is removing element by content. Lets say one
+wishes to delete 100 from nonempty list the syntax of the command
+should be
+
+.. #[[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]]
+
+::
+
+ nonempty.remove(100)
+
+but what if there were two 100's. To check that lets do a small
+experiment. ::
+
+ nonempty.append('spam')
+ nonempty
+ 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 }}}
+
+
+In this tutorial we came across a sequence data type called lists. ::
+
+ * We learned how to create lists.
+ * How to access lists.
+ * Append elements to list.
+ * Delete Element from list.
+ * And Checking list length.
+
+
+
+{{{ show Sponsored by Fossee Slide }}}
+
+This tutorial was created as a part of FOSSEE project.
+
+I hope you found this tutorial 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
new file mode 100644
index 0000000..f7cb690
--- /dev/null
+++ b/getting_started_with_lists/slides.org
@@ -0,0 +1,100 @@
+#+LaTeX_CLASS: beamer
+#+LaTeX_CLASS_OPTIONS: [presentation]
+#+BEAMER_FRAME_LEVEL: 1
+
+#+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
+
+#+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
+
+#+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
+
+
+* Outline
+ - How to create lists
+ - Structure of lists
+ - Access list elements
+ - Append elements to lists
+ - Deleting elements from lists
+
+
+* 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
new file mode 100644
index 0000000..42c6f0a
--- /dev/null
+++ b/getting_started_with_lists/slides.tex
@@ -0,0 +1,149 @@
+% Created 2010-11-10 Wed 12:22
+\documentclass[presentation]{beamer}
+\usepackage[latin1]{inputenc}
+\usepackage[T1]{fontenc}
+\usepackage{fixltx2e}
+\usepackage{graphicx}
+\usepackage{longtable}
+\usepackage{float}
+\usepackage{wrapfig}
+\usepackage{soul}
+\usepackage{t1enc}
+\usepackage{textcomp}
+\usepackage{marvosym}
+\usepackage{wasysym}
+\usepackage{latexsym}
+\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}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
+\begin{document}
+
+\maketitle
+
+
+
+
+
+
+
+
+
+
+\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}
+\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}
+
+\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-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}
+
+ \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}