| author | Puneeth Chaganti <punchagan@fossee.in> |
| Thu, 11 Nov 2010 09:34:21 +0530 | |
| changeset 463 | 192559461dcb |
| parent 421 | c4c5d1123f07 |
| permissions | -rw-r--r-- |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
1 |
#+LaTeX_CLASS: beamer |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
2 |
#+LaTeX_CLASS_OPTIONS: [presentation] |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
3 |
#+BEAMER_FRAME_LEVEL: 1 |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
4 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
5 |
#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
6 |
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
7 |
#+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 |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
8 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
9 |
#+LaTeX_CLASS: beamer |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
10 |
#+LaTeX_CLASS_OPTIONS: [presentation] |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
11 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
12 |
#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
13 |
#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
14 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
15 |
#+LaTeX_HEADER: \usepackage{listings}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
16 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
17 |
#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
18 |
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
19 |
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
20 |
|
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
21 |
#+TITLE: Manipulating Lists |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
22 |
#+AUTHOR: FOSSEE |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
23 |
#+EMAIL: |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
24 |
#+DATE: |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
25 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
26 |
#+DESCRIPTION: |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
27 |
#+KEYWORDS: |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
28 |
#+LANGUAGE: en |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
29 |
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
30 |
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
31 |
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
33 |
* Outline |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
34 |
In this session we shall be looking at |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
35 |
- Concatenating lists |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
36 |
- Obtaining parts of lists |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
37 |
- Sorting lists |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
38 |
- Reversing lists |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
39 |
* Question 1 |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
40 |
Obtain the primes less than 10, from the list ~primes~. |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
* Solution 1 |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
#+begin_src python |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
43 |
primes[0:4] |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
44 |
#+end_src python |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
45 |
* Slicing |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
46 |
#+begin_src python |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
47 |
p[start:stop] |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
48 |
#+end_src python |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
49 |
- Returns all elements of ~p~ between ~start~ and ~stop~ |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
50 |
- The element with index equal to ~stop~ is *not* included. |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
51 |
* Question 2 |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
52 |
Obtain all the multiples of three from the list ~num~. |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
53 |
* Solution 2 |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
54 |
#+begin_src python |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
55 |
num[::3] |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
56 |
#+end_src python |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
57 |
* Question 3 |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
58 |
Given a list of marks of students in an examination, obtain a list |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
59 |
with marks in descending order. |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
60 |
#+begin_src python |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
61 |
marks = [99, 67, 47, 100, 50, 75, 62] |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
62 |
#+end_src python |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
63 |
* Solution 3 |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
64 |
#+begin_src python |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
65 |
sorted(marks)[::-1] |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
66 |
#+end_src python |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
67 |
OR |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
68 |
#+begin_src python |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
69 |
sorted(marks, reverse=True) |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
70 |
#+end_src python |
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
71 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
72 |
* Summary |
|
421
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
73 |
In this tutorial session we learnt |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
74 |
+ Obtaining parts of lists using slicing and striding |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
75 |
+ List concatenation |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
76 |
+ Sorting lists |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
77 |
+ Reversing lists |
|
c4c5d1123f07
Cleaned up manipulating lists.
Puneeth Chaganti <punchagan@fossee.in>
parents:
312
diff
changeset
|
78 |
|
|
312
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
79 |
* Thank you! |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
80 |
#+begin_latex |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
81 |
\begin{block}{}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
82 |
\begin{center}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
83 |
This spoken tutorial has been produced by the |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
84 |
\textcolor{blue}{FOSSEE} team, which is funded by the
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
85 |
\end{center}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
86 |
\begin{center}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
87 |
\textcolor{blue}{National Mission on Education through \\
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
88 |
Information \& Communication Technology \\ |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
89 |
MHRD, Govt. of India}. |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
90 |
\end{center}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
91 |
\end{block}
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
92 |
#+end_latex |
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
93 |
|
|
8cb703eee88d
Manipulating lists LO - script and questions.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
94 |