summaryrefslogtreecommitdiff
path: root/getting-started-with-lists
diff options
context:
space:
mode:
Diffstat (limited to 'getting-started-with-lists')
-rw-r--r--getting-started-with-lists/getting_started_with_lists.rst137
-rw-r--r--getting-started-with-lists/quickref.tex8
-rw-r--r--getting-started-with-lists/slides.tex106
3 files changed, 251 insertions, 0 deletions
diff --git a/getting-started-with-lists/getting_started_with_lists.rst b/getting-started-with-lists/getting_started_with_lists.rst
new file mode 100644
index 0000000..a82de02
--- /dev/null
+++ b/getting-started-with-lists/getting_started_with_lists.rst
@@ -0,0 +1,137 @@
+Hello friends and welcome to the tutorial on getting started with
+lists.
+
+ {{{ Show the slide containing title }}}
+
+ {{{ 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
+ * Deleting 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 there order has a meaning.
+
+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.
+
+* Filled lists
+
+Lets now define a list, nonempty and fill it with some random elements.
+
+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 have 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
+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. Example ::
+
+ list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4]
+
+We access list elements using the number of 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]
+
+We can also access the elememts from the end using negative indices ::
+
+ 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
+
+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 being 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
+should be ::
+
+ a.remove(100)
+
+but what if their were two 100's. To check that lets do a small
+experiment. ::
+
+ a.append('spam')
+ a
+ a.remove('spam')
+ a
+
+If we check a 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.
+
+
+{{{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.
+
+
+
+{{{ 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/quickref.tex b/getting-started-with-lists/quickref.tex
new file mode 100644
index 0000000..b26d168
--- /dev/null
+++ b/getting-started-with-lists/quickref.tex
@@ -0,0 +1,8 @@
+Creating a linear array:\\
+{\ex \lstinline| x = linspace(0, 2*pi, 50)|}
+
+Plotting two variables:\\
+{\ex \lstinline| plot(x, sin(x))|}
+
+Plotting two lists of equal length x, y:\\
+{\ex \lstinline| plot(x, y)|}
diff --git a/getting-started-with-lists/slides.tex b/getting-started-with-lists/slides.tex
new file mode 100644
index 0000000..df1462c
--- /dev/null
+++ b/getting-started-with-lists/slides.tex
@@ -0,0 +1,106 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Tutorial slides on Python.
+%
+% Author: FOSSEE
+% Copyright (c) 2009, FOSSEE, IIT Bombay
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\documentclass[14pt,compress]{beamer}
+%\documentclass[draft]{beamer}
+%\documentclass[compress,handout]{beamer}
+%\usepackage{pgfpages}
+%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
+
+% Modified from: generic-ornate-15min-45min.de.tex
+\mode<presentation>
+{
+ \usetheme{Warsaw}
+ \useoutertheme{infolines}
+ \setbeamercovered{transparent}
+}
+
+\usepackage[english]{babel}
+\usepackage[latin1]{inputenc}
+%\usepackage{times}
+\usepackage[T1]{fontenc}
+
+\usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler}
+\usepackage[scaled=.95]{helvet}
+
+\definecolor{darkgreen}{rgb}{0,0.5,0}
+
+\usepackage{listings}
+\lstset{language=Python,
+ basicstyle=\ttfamily\bfseries,
+ commentstyle=\color{red}\itshape,
+ stringstyle=\color{darkgreen},
+ showstringspaces=false,
+ keywordstyle=\color{blue}\bfseries}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Macros
+\setbeamercolor{emphbar}{bg=blue!20, fg=black}
+\newcommand{\emphbar}[1]
+{\begin{beamercolorbox}[rounded=true]{emphbar}
+ {#1}
+ \end{beamercolorbox}
+}
+\newcounter{time}
+\setcounter{time}{0}
+\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
+
+\newcommand{\typ}[1]{\lstinline{#1}}
+
+\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
+
+% Title page
+\title{Your Title Here}
+
+\author[FOSSEE] {FOSSEE}
+
+\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
+\date{}
+
+% DOCUMENT STARTS
+\begin{document}
+
+\begin{frame}
+ \maketitle
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Outline}
+ \begin{itemize}
+ \item
+ \end{itemize}
+\end{frame}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% All other slides here. %%
+%% The same slides will be used in a classroom setting. %%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\begin{frame}[fragile]
+ \frametitle{Summary}
+ \begin{itemize}
+ \item
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Thank you!}
+ \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}