From 0ffcfc3b4283563435746f2dde1dfef85e363fd0 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 16:07:33 +0530 Subject: Cleaned up manipulating lists. --- manipulating-lists/script.rst | 90 +++++++++++++------ manipulating-lists/slides.org | 99 ++++++++------------- manipulating-lists/slides.tex | 196 ++++++++++++++++++++++++++---------------- 3 files changed, 222 insertions(+), 163 deletions(-) diff --git a/manipulating-lists/script.rst b/manipulating-lists/script.rst index 6d7d4b2..ba0bfa3 100644 --- a/manipulating-lists/script.rst +++ b/manipulating-lists/script.rst @@ -22,13 +22,12 @@ Script Hello friends. Welcome to this spoken tutorial on Manipulating Lists. - {{{ Show the slide containing the outline }}} We have already learnt a lot about Lists in Python. In this tutorial, we will learn more about advanced features of Lists in Python. We will -see in detail how to concatenate two lists, slicing and striding of -lists, methods to sort and reverse the list. +see how to concatenate two lists, details of slicing and striding of +lists, methods to sort and reverse lists. {{{ Shift to terminal and start ipython }}} @@ -40,8 +39,8 @@ on the terminal We already know what Lists are in Python, how to access individual elements in the list and some of the functions that can be run on the -lists like max, min, sum len and so on. Now let us learn some of the -basic operations that can be performed on Lists. +lists like ``max, min, sum, len`` and so on. Now let us learn some of +the basic operations that can be performed on Lists. We already know how to access individual elements in a List. But what if we have a scenario where we need to get a part of the entire list @@ -64,6 +63,18 @@ included and end index is not included. So in the above case, 11 which was the element with the index 4 was included but 23 which was the element with index 8 was excluded. +Following is an exercise you must do. + +%% %% Obtain the primes less than 10, from the list ``primes``. + +Please, pause the video here, do the exercise and then resume. + +:: + + primes[0:4] + +will give us the primes below 10. + Generalizing, we can obtain a slice of the list "p" from the index "start" upto the index "end" but excluding "end" with the following syntax @@ -79,12 +90,12 @@ obtained. Say we have:: num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] If we want to obtain all the odd numbers less than 10 from the list -"num" we have to start from element with index 1 upto the index 10 in +``num`` we have to start from element with index 1 upto the index 10 in steps of 2:: num[1:10:2] -So if we don't specify the step it is by default 1. Similary there are +When no step is specified, it is assumed to be 1. Similarly, there are default values for start and stop indices as well. If we don't specify the start index it is implicitly taken as the first element of the list:: @@ -105,6 +116,19 @@ gives all the elements starting from the 10th element in the list gives us all the even numbers in the list "num". +Following is an exercise that you must do. + +%% %% Obtain all the multiples of three from the list ``num``. + +Please, pause the video here. Do the exercise and then continue. + +:: + + num[::3] + +gives us all the multiples of 3 from the list, since every third +element in it, starting from 0, is divisible by 3. + The other basic operation that we can perform on list is concatenation of two or more lists. We can combine two lists by using the "plus" operator. Say we have @@ -122,17 +146,16 @@ list. We can store this list in a new variable:: c It is important to observe that the "plus" operator always returns a -new list without touching anything in the existing lists which are the -operands of the concatenation operation. +new list without altering the lists being concatenated in any way. -We know that list is a collection of data. Whenever we have a -collection we run into situations where we want to start the +We know that a list is a collection of data. Whenever we have a +collection we run into situations where we want to sort the collection. Lists support sort method which sorts the list inplace:: a = [5, 1, 6, 7, 7, 10] a.sort() -Now the contents of the list "a" will be:: +Now the contents of the list ``a`` will be:: a [1, 5, 6, 7, 7, 10] @@ -164,27 +187,46 @@ itself. Lets see the list "a":: a [5, 4, 3, 2, 1] -But again the original list is lost. If we want to obtain the reverse -of a list keeping the original list intact we can use the Python -built-in function reversed. reversed function returns a new list which -is the reverse of the list which was passed as the argument to the -reversed function:: +But again the original list is lost. +.. #[punch: removed reversed, since it returns an iterator] - a = [1, 2, 3, 4, 5] - reversed(a) +To reverse a list, we could use striding with negative indexing.:: + + a[::-1] We can also store this new reversed list in another list variable. +Following is an (are) exercise(s) that you must do. + +%% %% Given a list of marks of students in an examination, obtain a + list with marks in descending order. + :: + + marks = [99, 67, 47, 100, 50, 75, 62] + +Please, pause the video here. Do the exercise(s) and then continue. + +:: + + sorted(marks)[::-1] + +OR + +:: + + sorted(marks, reverse = True) + + + {{{ Show summary slide }}} This brings us to the end of another session. In this tutorial session we learnt - * How to define strings - * Different types of defining a string - * String concatenation and repeatition - * Accessing individual elements of the string - * Immutability of strings + * Obtaining parts of lists using slicing and striding + * List concatenation + * Sorting lists + * Reversing lists {{{ Show the "sponsored by FOSSEE" slide }}} diff --git a/manipulating-lists/slides.org b/manipulating-lists/slides.org index 5d2ce93..c0eea62 100644 --- a/manipulating-lists/slides.org +++ b/manipulating-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: Accessing parts of arrays +#+TITLE: Manipulating Lists #+AUTHOR: FOSSEE #+EMAIL: #+DATE: @@ -28,83 +28,54 @@ #+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 +#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate * Outline - - Manipulating one and multi dimensional arrays - - Access and change individual elements - - Access and change rows and columns - - Slicing and striding on arrays to access chunks - - Read images into arrays and manipulations -* Sample Arrays - #+begin_src python - In []: A = array([12, 23, 34, 45, 56]) - - In []: C = array([[11, 12, 13, 14, 15], - [21, 22, 23, 24, 25], - [31, 32, 33, 34, 35], - [41, 42, 43, 44, 45], - [51, 52, 53, 54, 55]]) - - #+end_src + In this session we shall be looking at + - Concatenating lists + - Obtaining parts of lists + - Sorting lists + - Reversing lists * Question 1 - Change the last column of ~C~ to zeroes. + Obtain the primes less than 10, from the list ~primes~. * Solution 1 #+begin_src python - In []: C[:, -1] = 0 - #+end_src + primes[0:4] + #+end_src python +* Slicing + #+begin_src python + p[start:stop] + #+end_src python + - Returns all elements of ~p~ between ~start~ and ~stop~ + - The element with index equal to ~stop~ is *not* included. * Question 2 - Change ~A~ to ~[11, 12, 13, 14, 15]~. + Obtain all the multiples of three from the list ~num~. * Solution 2 #+begin_src python - In []: A[:] = [11, 12, 13, 14, 15] - #+end_src -* squares.png - #+begin_latex - \begin{center} - \includegraphics[scale=0.6]{squares} - \end{center} - #+end_latex + num[::3] + #+end_src python * Question 3 - - obtain ~[22, 23]~ from ~C~. - - obtain ~[11, 21, 31, 41]~ from ~C~. - - obtain ~[21, 31, 41, 0]~. -* Solution 3 - #+begin_src python - In []: C[1, 1:3] - In []: C[0:4, 0] - In []: C[1:5, 0] - #+end_src -* Question 4 - Obtain ~[[23, 24], [33, -34]]~ from ~C~ -* Solution 4 + Given a list of marks of students in an examination, obtain a list + with marks in descending order. #+begin_src python - In []: C[1:3, 2:4] - #+end_src -* Question 5 - Obtain the square in the center of the image -* Solution 5 + marks = [99, 67, 47, 100, 50, 75, 62] + #+end_src python +* Solution 3 #+begin_src python - In []: imshow(I[75:225, 75:225]) - #+end_src -* Question 6 - Obtain the following + sorted(marks)[::-1] + #+end_src python +OR #+begin_src python - [[12, 0], [42, 0]] - [[12, 13, 14], [0, 0, 0]] - #+end_src + sorted(marks, reverse=True) + #+end_src python -* Solution 6 - #+begin_src python - In []: C[::3, 1::3] - In []: C[::4, 1:4] - #+end_src * Summary - You should now be able to -- - - Manipulate 1D \& Multi dimensional arrays - - Access and change individual elements - - Access and change rows and columns - - Slice and stride on arrays - - Read images into arrays and manipulate them. + In this tutorial session we learnt + + Obtaining parts of lists using slicing and striding + + List concatenation + + Sorting lists + + Reversing lists + * Thank you! #+begin_latex \begin{block}{} diff --git a/manipulating-lists/slides.tex b/manipulating-lists/slides.tex index df1462c..5b02407 100644 --- a/manipulating-lists/slides.tex +++ b/manipulating-lists/slides.tex @@ -1,95 +1,141 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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 -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-11-09 Tue 16:07 +\documentclass[presentation]{beamer} \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{fixltx2e} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\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} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% 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} +\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{Manipulating Lists} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + +\begin{frame} +\frametitle{Outline} +\label{sec-1} + + In this session we shall be looking at +\begin{itemize} +\item Concatenating lists +\item Obtaining parts of lists +\item Sorting lists +\item Reversing lists +\end{itemize} +\end{frame} \begin{frame} - \maketitle +\frametitle{Question 1} +\label{sec-2} + + Obtain the primes less than 10, from the list \texttt{primes}. \end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-3} +\lstset{language=Python} +\begin{lstlisting} +primes[0:4] +\end{lstlisting} +\end{frame} \begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\frametitle{Slicing} +\label{sec-4} + +\lstset{language=Python} +\begin{lstlisting} +p[start:stop] +\end{lstlisting} +\begin{itemize} +\item Returns all elements of \texttt{p} between \texttt{start} and \texttt{stop} +\item The element with index equal to \texttt{stop} is \textbf{not} included. +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-5} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + Obtain all the multiples of three from the list \texttt{num}. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-6} +\lstset{language=Python} +\begin{lstlisting} +num[::3] +\end{lstlisting} +\end{frame} \begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\frametitle{Question 3} +\label{sec-7} + + Given a list of marks of students in an examination, obtain a list + with marks in descending order. +\lstset{language=Python} +\begin{lstlisting} +marks = [99, 67, 47, 100, 50, 75, 62] +\end{lstlisting} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 3} +\label{sec-8} + +\lstset{language=Python} +\begin{lstlisting} +sorted(marks)[::-1] +\end{lstlisting} +OR +\lstset{language=Python} +\begin{lstlisting} +sorted(marks, reverse=True) +\end{lstlisting} \end{frame} - \begin{frame} - \frametitle{Thank you!} +\frametitle{Summary} +\label{sec-9} + + In this tutorial session we learnt +\begin{itemize} +\item Obtaining parts of lists using slicing and striding +\item List concatenation +\item Sorting lists +\item Reversing lists +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-10} + \begin{block}{} \begin{center} This spoken tutorial has been produced by the -- cgit From fb1b64961cd3334451b36acd8b2ca20f90cc8043 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 16:14:58 +0530 Subject: Changes to manipulating lists quickref. --- manipulating-lists/quickref.tex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/manipulating-lists/quickref.tex b/manipulating-lists/quickref.tex index b26d168..d571a9e 100644 --- a/manipulating-lists/quickref.tex +++ b/manipulating-lists/quickref.tex @@ -1,8 +1,10 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +Slicing \& Striding a list:\\ +{\ex \lstinline| A[start:stop:step]|} \lstinline|stop| excluded -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +Sorting a list:\\ +{\ex \lstinline| sorted(A)|} -- returns new list +{\ex \lstinline| A.sort()|} -- in-place sort -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +Reversing a list:\\ +{\ex \lstinline| A[::-1]|} -- returns new list +{\ex \lstinline| A.reverse()|} -- in-place reverse -- cgit From 745629ef88f1e8b20970d0223fcc74c4dff9bd9b Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 16:16:55 +0530 Subject: Changes to progress.org. --- progress.org | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/progress.org b/progress.org index 6a058e0..d7f8b2a 100644 --- a/progress.org +++ b/progress.org @@ -39,9 +39,9 @@ | 6.4 LO: | loops | 2 | Punch | Anoop (Done) | | | 6.5 LO: | Assessment | 3 | Anoop | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| -| 7.1 LO: | manipulating lists | 3 | Madhu | Punch (pending) | | -| 7.2 LO: | manipulating strings | 2 | Punch | Amit(Done) | | -| 7.3 LO: | getting started with tuples | 2 | Nishanth | | | +| 7.1 LO: | manipulating lists | 3 | Madhu | Punch (Done) | | +| 7.2 LO: | manipulating strings | 2 | Punch | Amit (Done) | | +| 7.3 LO: | getting started with tuples | 2 | Nishanth | Punch (Pending) | | | 7.4 LO: | dictionaries | 2 | Anoop | Punch (Done) | | | 7.5 LO: | sets | 2 | Nishanth | | | | 7.6 LO: | Assessment | 3 | Amit | | | -- cgit From 5076929123682c93fe8e4940062efe9e929d7972 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 16:51:00 +0530 Subject: Cleaned up tuples LO. --- tuples/script.rst | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/tuples/script.rst b/tuples/script.rst index 5918643..ea1c2e1 100644 --- a/tuples/script.rst +++ b/tuples/script.rst @@ -1,15 +1,10 @@ .. Objectives .. ---------- -.. A - Students and teachers from Science and engineering backgrounds - B - Will learn what are tuples and why they are needed - Will learn the various methods of accessing elements in tuples - C - - D - - -.. #. what are tuples -.. #. comparison with lists -.. #. why are they needed +.. At the end of the tutorial, you will +.. #. have a clear understand of what tuples are +.. #. be able to compare them with lists +.. #. know why they are needed and where to use them .. Prerequisites @@ -25,7 +20,8 @@ Script ------ -Hello friends and welcome to the tutorial on Tuples +Hello friends and welcome to the tutorial on getting started with +tuples. {{{ Show the slide containing title }}} @@ -37,9 +33,10 @@ In this tutorial, we shall learn * their similarities and dissimilarities with lists * why are they needed -Let`s get started by defining a tuple. A tuple is defined by enclosing -parantheses around a sequence of items seperated by commas. It is similar to -defining a list except that parantheses are used instead of square brackets. +Let's get started by defining a tuple. A tuple is defined by enclosing +parentheses around a sequence of items seperated by commas. It is +similar to defining a list except that parentheses are used instead of +square brackets. :: t = (1, 2.5, "hello", -4, "world", 1.24, 5) @@ -66,10 +63,10 @@ we try to change an element in the tuple. t[2] = "Hello" We can see that, it raises an error saying tuple does not support item -assignment. It only implies that tuples are immutable or in simple words, -tuples cannot be changed. +assignment. Tuples are immutable, and cannot be changed after +creation. -But what is the use of tuples!!! +Then, what's the use of tuples? We shall understand that soon. But let us look at a simple problem of swapping values. @@ -110,8 +107,9 @@ Now let us do it the python way a b -We see that the values are swapped. -This idiom works for different datatypes also. +We see that the values are swapped. This idiom works for different +data-types also. + :: a = 2.5 @@ -120,8 +118,8 @@ This idiom works for different datatypes also. a b -Moreover this type of behaviour is straight forward and what you would expect -should happen naturally. +Moreover this type of behaviour is something that feels natural and +you'd expect to happen. This is possible because of the immutability of tuples. This process is called tuple packing and unpacking. @@ -136,10 +134,10 @@ What we see is a tuple with one element. 5, "hello", 2.5 -Now it is a tuple with two elements. +Now it is a tuple with three elements. So when we are actually typing two or more elements seperated by commas, those -elements are packed and a tuple is made from them. +elements are packed into a tuple. When you type :: @@ -165,9 +163,8 @@ we have learnt {{{ Show the "sponsored by FOSSEE" slide }}} -#[Nishanth]: Will add this line after all of us fix on one. This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou +Thank you -- cgit From 0796daee76accb09eb4e80c88693bf63bae48560 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 16:51:41 +0530 Subject: Changes to progress.org. --- progress.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/progress.org b/progress.org index d7f8b2a..14db2c2 100644 --- a/progress.org +++ b/progress.org @@ -41,9 +41,9 @@ |---------+----------------------------------------+-------+----------+-----------------+-----------| | 7.1 LO: | manipulating lists | 3 | Madhu | Punch (Done) | | | 7.2 LO: | manipulating strings | 2 | Punch | Amit (Done) | | -| 7.3 LO: | getting started with tuples | 2 | Nishanth | Punch (Pending) | | +| 7.3 LO: | getting started with tuples | 2 | Nishanth | Punch (Done) | | | 7.4 LO: | dictionaries | 2 | Anoop | Punch (Done) | | -| 7.5 LO: | sets | 2 | Nishanth | | | +| 7.5 LO: | sets | 2 | Nishanth | Punch (pending) | | | 7.6 LO: | Assessment | 3 | Amit | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| | 8.1 LO: | getting started with functions | 3 | Nishanth | | | -- cgit From 722ef6b819e8a375c388cc14963763471322ca91 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 17:15:24 +0530 Subject: Cleaned up sets LO. --- sets/script.rst | 19 +++++++++---------- sets/slides.org | 4 +++- sets/slides.tex | 5 +++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sets/script.rst b/sets/script.rst index 8f9c699..680e170 100644 --- a/sets/script.rst +++ b/sets/script.rst @@ -22,15 +22,15 @@ Script ------ -Hello friends and welcome to the tutorial on Sets - {{{ Show the slide containing title }}} +Hello friends and welcome to the tutorial on Sets + {{{ Show the slide containing the outline slide }}} In this tutorial, we shall learn - * sets + * sets * operations on sets Sets are data structures which contain unique elements. In other words, @@ -40,7 +40,7 @@ Lets look at how to input sets. type :: - a_list = [1, 2, 1, 4, 5, 6, 7] + a_list = [1, 2, 1, 4, 5, 6, 2] a = set(a_list) a @@ -55,7 +55,7 @@ f10 is the set of fibonacci numbers from 1 to 10. p10 is the set of prime numbers from 1 to 10. Various operations that we do on sets are possible here also. -The | character stands for union +The | (pipe) character stands for union :: f10 | p10 @@ -89,19 +89,19 @@ Sets also support checking of subsets. b = set([1, 2]) b < f10 -gives a True since b is a proper subset of f10. +gives a ``True`` since b is a proper subset of f10. Similarly, :: f10 < f10 -gives a False since f10 is not a proper subset. +gives a ``False`` since f10 is not a proper subset. hence the right way to do would be :: f10 <= f10 -and we get a True since every set is a subset of itself. +and we get a ``True`` since every set is a subset of itself. Sets can be iterated upon just like lists and tuples. :: @@ -122,7 +122,7 @@ shows 5. And 1 in f10 2 in f10 -prints True and False respectively +prints ``True`` and ``False`` respectively The order in which elements are organised in a set is not to be relied upon since sets do not support indexing. Hence, slicing and striding are not valid @@ -161,7 +161,6 @@ we have learnt {{{ Show the "sponsored by FOSSEE" slide }}} -#[Nishanth]: Will add this line after all of us fix on one. This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. diff --git a/sets/slides.org b/sets/slides.org index d0b007c..9f056d9 100644 --- a/sets/slides.org +++ b/sets/slides.org @@ -43,8 +43,10 @@ for mark in marks_set: marks.remove(mark) - # we are now left with only duplicates in the list marks + # we are now left with only duplicates + # in the list marks duplicates = set(marks) + #+end_src * Summary You should now be able to -- diff --git a/sets/slides.tex b/sets/slides.tex index b1b2eda..945af18 100644 --- a/sets/slides.tex +++ b/sets/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-10-10 Sun 23:53 +% Created 2010-11-09 Tue 17:14 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -67,7 +67,8 @@ marks_set = set(marks) for mark in marks_set: marks.remove(mark) -# we are now left with only duplicates in the list marks +# we are now left with only duplicates +# in the list marks duplicates = set(marks) \end{lstlisting} \end{frame} -- cgit From 79247bca3fe19df669f12fc48e34d5ed906b4dfc Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Tue, 9 Nov 2010 17:15:49 +0530 Subject: Changes to progress.org. --- progress.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress.org b/progress.org index 14db2c2..2eff2af 100644 --- a/progress.org +++ b/progress.org @@ -43,7 +43,7 @@ | 7.2 LO: | manipulating strings | 2 | Punch | Amit (Done) | | | 7.3 LO: | getting started with tuples | 2 | Nishanth | Punch (Done) | | | 7.4 LO: | dictionaries | 2 | Anoop | Punch (Done) | | -| 7.5 LO: | sets | 2 | Nishanth | Punch (pending) | | +| 7.5 LO: | sets | 2 | Nishanth | Punch (Done) | | | 7.6 LO: | Assessment | 3 | Amit | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| | 8.1 LO: | getting started with functions | 3 | Nishanth | | | -- cgit From 38a80970b7b39d838e1971f0d5025490a4793baa Mon Sep 17 00:00:00 2001 From: Amit Sethi Date: Tue, 9 Nov 2010 17:37:03 +0530 Subject: Changes to slides on plotting data --- plotting-data/script.rst | 6 +++--- plotting-data/slides.org | 8 +++++--- plotting-data/slides.tex | 11 +++++++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/plotting-data/script.rst b/plotting-data/script.rst index 70e5f06..96ad313 100644 --- a/plotting-data/script.rst +++ b/plotting-data/script.rst @@ -167,13 +167,13 @@ of errorbar.:: In this tutorial we have learnt : -1. How to declare a sequence of number , specifically the kind of sequence we learned was a list. +1. How to declare a sequence of numbers. -2. Plotting experimental data extending our knowledge from mathematical functions. +2. Plotting experimental data. 3. The various options available for plotting dots instead of lines. -4. Plotting experimental data such that we can also represent error. We did this using the errorbar() function. +4. Plotting experimental data such that we can also represent error. {{{ Show the "sponsored by FOSSEE" slide }}} diff --git a/plotting-data/slides.org b/plotting-data/slides.org index 9545e41..0a89ae8 100644 --- a/plotting-data/slides.org +++ b/plotting-data/slides.org @@ -75,12 +75,14 @@ * Plotting Error bar - : In[]: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, - : fmt='b.') + : In[]: errorbar(L,tsquare,xerr=delta_L, + : yerr=delta_T,fmt='b.') + * Summary : L = [0.1, 0.2, 0.3, 0.4, 0.5, | : 0.6, 0.7, 0.8, 0.9] : plot(x,y,'o') : plot(x,y,'.') - : errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') + : errorbar(L,tsquare,xerr=delta_L, + : yerr=delta_T, fmt='b.') diff --git a/plotting-data/slides.tex b/plotting-data/slides.tex index b03d4e1..87fa8fb 100644 --- a/plotting-data/slides.tex +++ b/plotting-data/slides.tex @@ -1,4 +1,4 @@ -% Created 2010-11-09 Tue 15:09 +% Created 2010-11-09 Tue 17:34 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -121,9 +121,11 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} \begin{verbatim} - In[]: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, - fmt='b.') + In[]: errorbar(L,tsquare,xerr=delta_L, + yerr=delta_T,fmt='b.') \end{verbatim} + + \end{frame} \begin{frame}[fragile] \frametitle{Summary} @@ -134,7 +136,8 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries} 0.6, 0.7, 0.8, 0.9] plot(x,y,'o') plot(x,y,'.') - errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') + errorbar(L,tsquare,xerr=delta_L, + yerr=delta_T, fmt='b.') \end{verbatim} \end{frame} -- cgit From 548f1dca6c60f8e59bf494be62f616ed39f332d6 Mon Sep 17 00:00:00 2001 From: Anoop Jacob Thomas Date: Tue, 9 Nov 2010 19:03:47 +0530 Subject: reviewed getting started with lists. --- getting-started-with-lists/script.rst | 80 +++++++++++++------- getting-started-with-lists/slides.tex | 138 ++++++++++++---------------------- 2 files changed, 100 insertions(+), 118 deletions(-) diff --git a/getting-started-with-lists/script.rst b/getting-started-with-lists/script.rst index bc44470..37d4ad7 100644 --- a/getting-started-with-lists/script.rst +++ b/getting-started-with-lists/script.rst @@ -20,17 +20,19 @@ .. #. basic datatypes .. Author : Amit - Internal Reviewer : + Internal Reviewer : Anoop Jacob Thomas External Reviewer : Checklist 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 title }}} - {{{ Show the slide containing the outline slide }}} In this tutorial we will be getting acquainted with a python data @@ -40,12 +42,16 @@ structure called lists. We will learn :: * Structure of lists * Access list elements * Append elements to lists - * Deleting elements from 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 there 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 :: @@ -55,43 +61,50 @@ shell type :: This is an empty list without any elements. -* Filled lists +.. #[[Anoop: the document has to be continous, without any + subheadings, removing * Filled lists]] -Lets now define a list, nonempty and fill it with some random elements. +Lets now see how to define a non-empty list. We do it as,:: -nonempty = ['spam', 'eggs', 100, 1.234] + 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. - - +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 +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. Example :: +in lists. Thus lists can also contain other lists. + +.. #[[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] -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. :: +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] +.. #[[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 :: 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. +-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. :: @@ -102,10 +115,8 @@ We can append elements to the end of a list using append command. :: 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 :: +nonempty. In this case it 6 :: len(nonempty) @@ -121,11 +132,20 @@ There are two ways of doing it. One is by using index. :: 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 :: - - nonempty.remove(100) +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]] -but what if their were two 100's. To check that lets do a small +:: + + nonempty.remove(100) + +but what if there were two 100's. To check that lets do a small experiment. :: nonempty.append('python') @@ -133,10 +153,14 @@ experiment. :: nonempty.remove('python') nonempty -If we check a now we will see that the first occurence 'spam' is removed +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]] {{{Slide for Summary }}} @@ -151,7 +175,7 @@ In this tutorial we came across a sequence data type called lists. :: -{{{ Sponsored by Fossee Slide }}} +{{{ show Sponsored by Fossee Slide }}} This tutorial was created as a part of FOSSEE project. @@ -159,7 +183,7 @@ 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.tex b/getting-started-with-lists/slides.tex index df1462c..0465d54 100644 --- a/getting-started-with-lists/slides.tex +++ b/getting-started-with-lists/slides.tex @@ -1,106 +1,64 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%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 -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-11-09 Tue 17:41 +\documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} -%\usepackage{times} \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 +\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} +\begin{document} -\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}} +\maketitle -\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} +\frametitle{Tutorial Plan} +\label{sec-1} +\begin{itemize} + +\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 \end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-2} -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% 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} + l=[1,2,3,4] + l[-1] + l.append(5) + del(l\footnote{FOOTNOTE DEFINITION NOT FOUND: 2 }) + len(l) \end{frame} \end{document} -- cgit From dcc19f638a46eec9fe1d9d4879d320057d6bfee5 Mon Sep 17 00:00:00 2001 From: Anoop Jacob Thomas Date: Tue, 9 Nov 2010 19:05:11 +0530 Subject: changed progress.org. --- progress.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/progress.org b/progress.org index 2eff2af..46b6f50 100644 --- a/progress.org +++ b/progress.org @@ -9,11 +9,11 @@ | 1.8 LO: | module level assessment | 3 | Madhu | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| | 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | | -| 2.3 LO: | plotting the data | 3 | Amit | Pending | | +| 2.3 LO: | plotting the data | 3 | Amit | Anoop (Done) | | | 2.4 LO: | other types of plots | 3 | Anoop | Punch (Done) | | | 2.5 LO: | module level assessment | 3 | Nishanth | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| -| 3.1 LO: | getting started with lists | 2 | Amit | Pending | | +| 3.1 LO: | getting started with lists | 2 | Amit | Anoop(Done) | | | 3.2 LO: | getting started with =for= | 2 | Anoop | Nishanth (Done) | | | 3.3 LO: | getting started with strings | 2 | Madhu | | | | 3.4 LO: | getting started with files | 3 | Punch | Anoop(Done) | | -- cgit