#+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: #+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 * #+begin_latex \begin{center} \vspace{12pt} \textcolor{blue}{\huge Manipulating Lists} \end{center} \vspace{18pt} \begin{center} \vspace{10pt} \includegraphics[scale=0.95]{../images/fossee-logo.png}\\ \vspace{5pt} \scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ \scriptsize Funded by National Mission on Education through ICT\\ \scriptsize MHRD,Govt. of India\\ \includegraphics[scale=0.30]{../images/iitb-logo.png}\\ \end{center} #+end_latex * Objectives At the end of this tutorial, you will be able to, - Concatenate two lists. - Learn the details of slicing and striding of lists. - Sort and reverse lists. * Pre-requisite Spoken tutorial on - - Getting started with Lists. * Exercise 1 Obtain the primes less than 10, from the list ~primes~. * 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. * Exercise 2 Obtain all the multiples of three from the list ~num~. * Solution 2 #+begin_src python num[::3] #+end_src python * Exercise 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 * Summary In this tutorial, we have learnt to, - Obtain parts of lists using slicing and striding. - Concatenate lists using the ``plus'' operator. - Sort lists using the ``sort'' method. - Use the method ``reverse'' to reverse the lists. * Evaluation 1. Given the list primes, primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29], How do you obtain the last 4 primes? 2. Given a list, p, of unknown length, obtain the first 3 (or all, if there are fewer) characters of it. 3. ``reversed'' function reverses a list in place. True or False? * Solutions 1. primes[-4:] 2. p[:3] 3. False * #+begin_latex \begin{block}{} \begin{center} \textcolor{blue}{\Large THANK YOU!} \end{center} \end{block} \begin{block}{} \begin{center} For more Information, visit our website\\ \url{http://fossee.in/} \end{center} \end{block} #+end_latex