manipulating-lists/slides.org
author Puneeth Chaganti <punchagan@fossee.in>
Thu, 11 Nov 2010 02:55:20 +0530
changeset 459 68c324a9981c
parent 421 c4c5d1123f07
permissions -rw-r--r--
Reviewed using sage to teach

#+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:    Manipulating Lists
#+AUTHOR:    FOSSEE
#+EMAIL:     
#+DATE:    

#+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
#+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate

* Outline
  In this session we shall be looking at 
  - Concatenating lists
  - Obtaining parts of lists
  - Sorting lists
  - Reversing lists
* Question 1
  Obtain the primes less than 10, from the list ~primes~. 
* Solution 1
  #+begin_src python
    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
  Obtain all the multiples of three from the list ~num~.
* Solution 2
  #+begin_src python
    num[::3]  
  #+end_src python
* Question 3
  Given a list of marks of students in an examination, obtain a list
  with marks in descending order.
  #+begin_src python
    marks = [99, 67, 47, 100, 50, 75, 62]
  #+end_src python
* Solution 3
  #+begin_src python
    sorted(marks)[::-1]
  #+end_src python
OR
  #+begin_src python
    sorted(marks, reverse=True)
  #+end_src python

* Summary
  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}{}
  \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