Download as pdf or txt
Download as pdf or txt
You are on page 1of 69

Arihant computer science term 2

question bank 2021 22 2021st Edition


Arihant
Visit to download the full and correct content document:
https://ebookstep.com/product/arihant-computer-science-term-2-question-bank-2021-
22-2021st-edition-arihant/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

■■■■■■■■■■■■■ ■■■■■■■ ■■ Computer Science. ■■■■,


■■■■■■■■■■■■ ■ data science 1st Edition ■■■■■■■■
■■■■■■■■ ■■■■

https://ebookstep.com/download/ebook-43189802/

■■■ ■■ Computer Science ■■■■■■■■■■■ ■■■■■■■ 1st Editio


■■■■■■ ■■■■■■■■

https://ebookstep.com/download/ebook-33802828/

Crash Course Computer Science Worksheet 1st Edition


Carrie Anne Philbin

https://ebookstep.com/product/crash-course-computer-science-
worksheet-1st-edition-carrie-anne-philbin/

■■■■■■■■■■■■ ■■■■■■ Computer Science ■■ ■■■■■ Python


1st Edition ■■■■■ ■■■■■

https://ebookstep.com/download/ebook-10543478/
Intro to Python for Computer Science and Data Science:
Learning to Program with AI, Big Data and The Cloud 1st
Edition Deitel

https://ebookstep.com/product/intro-to-python-for-computer-
science-and-data-science-learning-to-program-with-ai-big-data-
and-the-cloud-1st-edition-deitel/

■■■■■■■■■■■■■ ■■■■■■■ ■■ Computer Science ■■■ ■■■ ■


■■■■■■■■■■■■ ■ ■■■■■■■■■■■■ 1st Edition ■■■■■■■■
■■■■■■■■ ■■■■

https://ebookstep.com/download/ebook-7049022/

Computer Science ■■■ ■■■■■■■■■■■■ ■■■■■■■■ ■■■ ■■■


■■■■■ ■■■■■ ■ ■■■■■■■■■■ ■■■■■■ ■ ■■■■■■■■■■ 1st
Edition ■■■■ ■■■■■■■■

https://ebookstep.com/download/ebook-49055652/

Seducción 2 Amor en Londres 2021st Edition Lauren Smith

https://ebookstep.com/product/seduccion-2-amor-en-londres-2021st-
edition-lauren-smith/

Seducción 2 Amor en Londres 2021st Edition Lauren Smith

https://ebookstep.com/product/seduccion-2-amor-en-londres-2021st-
edition-lauren-smith-3/
CBSE Term II
2022
Computer
Science
Class
XI
Complete Theory Covering NCERT

Case Based Questions

Short/Long Answer Type Questions

3 Practice Papers with Explanations

Author
Neetu Gaikwad

ARIHANT PRAKASHAN (School Division Series)


CBSE Term II
2022

ARIHANT PRAKASHAN (School Division Series)

© Publisher
No part of this publication may be re-produced, stored in a retrieval system or by any means,
electronic, mechanical, photocopying, recording, scanning, web or otherwise without the written
permission of the publisher. Arihant has obtained all the information in this book from the sources
believed to be reliable and true. However, Arihant or its editors or authors or illustrators don’t take any
responsibility for the absolute accuracy of any information published and the damage or loss suffered
thereupon.
All disputes subject to Meerut (UP) jurisdiction only.

Administrative & Production Offices


Regd. Office
‘Ramchhaya’ 4577/15, Agarwal Road, Darya Ganj, New Delhi -110002
Tele: 011- 47630600, 43518550

Head Office
Kalindi, TP Nagar, Meerut (UP) - 250002, Tel: 0121-7156203, 7156204
Sales & Support Offices
Agra, Ahmedabad, Bengaluru, Bareilly, Chennai, Delhi, Guwahati,
Hyderabad, Jaipur, Jhansi, Kolkata, Lucknow, Nagpur & Pune.

ISBN : 978-93-25796-87-4
PO No : TXT-XX-XXXXXXX-X-XX
Published by Arihant Publications (India) Ltd.
For further information about the books published by Arihant, log on to
www.arihantbooks.com or e-mail at info@arihantbooks.com

Follow us on
CBSE Term II
2022

Contents
CHAPTER
Lists in Python -

CHAPTER
Tuples -

CHAPTER
Dictionary -

CHAPTER
Introduction to Python Modules -

CHAPTER
Society, Law and Ethics -

Practice Papers - -

Watch Free Learning Videos


Subscribe arihant Channel

þ Video Solutions of CBSE Sample Papers


þ Chapterwise Important MCQs
þ CBSE Updates
CBSE Term II
2022

Syllabus
CBSE Term II Class XI

Computer Science
Marks
. Computational Thinking and Programming -
. Society, Law and Ethics
Total

UNIT II: COMPUTATIONAL THINKING AND PROGRAMMING


Ÿ Lists: introduction, indexing, list operations concatenation, repetition, membership
slicing , traversing a list using loops, built-in functions: len , list , append , extend ,
insert , count , index , remove , pop , reverse , sort , sorted , min , max , sum ;
nested lists, suggested programs: finding the maximum, minimum, mean of numeric
values stored in a list; linear search on list of numbers and counting the frequency of
elements in a list
Ÿ Tuples: introduction, indexing, tuple operations concatenation, repetition,
membership slicing , built-in functions: len , tuple , count , index , sorted ,
min , max , sum ; tuple assignment, nested tuple, suggested programs: finding the
minimum, maximum, mean of values stored in a tuple; linear search on a tuple of
numbers, counting the frequency of elements in a tuple
Ÿ Dictionary: introduction, accessing items in a dictionary using keys, mutability of
dictionary adding a new item, modifying an existing item , traversing a dictionary,
built-in functions: len , dict , keys , values , items , get , update , del , clear ,
fromkeys , copy , pop , popitem , setdefault , max , min , count , sorted ,
copy ; suggested programs : count the number of times a character appears in a
given string using a dictionary, create a dictionary with names of employees, their
salary and access them
Ÿ Introduction to Python modules: Importing module using import <module> and
using from statement, Importing math module pi, e, sqrt, ceil, floor, pow, fabs, sin,
cos, tan ; random module random, randint, randrange , statistics module mean,
median, mode
CBSE Term II
2022

Ÿ UNIT III: SOCIETY, LAW AND ETHICS


Ÿ Digital Footprints
Ÿ Digital society and Netizen: net etiquettes, communication etiquettes, social media
etiquettes
Ÿ Data protection: Intellectual Property Right copyright, patent, trademark , violation
of IPR plagiarism, copyright infringement, trademark infringement , open source
softwares and licensing Creative Commons, GPL and Apache
Ÿ Cyber-crime: definition, hacking, eavesdropping, phishing and fraud emails,
ransomware, preventing cyber crime
Ÿ Cyber safety: safely browsing the web, identity protection, confidentiality, cyber trolls
and bullying.
Ÿ Safely accessing web sites: malware, viruses, Trojans, adware
Ÿ E-waste management: proper disposal of used electronic gadgets
Ÿ Indian Information Technology Act IT Act
Ÿ Technology Society: Gender and disability issues while teaching and using
computers
CBSE Circular
Acad - 51/2021, 05 July 2021

Exam Scheme Term I & II

dsUnh;
z ek/;fed f'k{kk cksMZ
(f'k{kk ea=ky;] Hkkjr ljdkj ds v/khu ,d Lok;r laxBu)
Hkkjr
CENTRAL BOARD OF SECONDARY EDUCATION
(An Autonomous Organisation under the Ministryof Education, Govt. of India)
dsUnh;
z ek/;fed f'k{kk cksMZ
(f'k{kk ea=ky;] Hkkjr ljdkj ds v/khu ,d Lok;r laxBu)

Hkkjr CENTRAL BOARD OF SECONDARY EDUCATION


(An Autonomous Organisation under the Ministryof Education, Govt. of India)

To cover this
situation, we
have given
both MCQs and
Subjective
Questions in
each Chapter.
dsUnh;
z ek/;fed f'k{kk cksMZ
(f'k{kk ea=ky;] Hkkjr ljdkj ds v/khu ,d Lok;r laxBu)

Hkkjr CENTRAL BOARD OF SECONDARY EDUCATION


(An Autonomous Organisation under the Ministryof Education, Govt. of India)
CBSE Term II Computer Science XI 1

CHAPTER 01

Lists in Python
In this Chapter...
l Creating a List l Membership Operators

l Accessing Lists l List Operations

l Traversing a List l Built-in Functions


l Comparison Operators

In Python, list is a type of container in data structures, which Syntax


is used to store multiple data at the same time. List acts as an new_list_name = list (sequence/string)
array which defined other languages such as C++, Java etc. Here, sequence includes tuples, lists etc.
List contains a sequence of heterogeneous elements which
makes it powerful tool in Python. It can store integer, string For example,
as well as object in a single list. It is also useful for >>>A = “PYTHON”
implementing stacks and queues. >>>A1 = list(A)
Lists are mutable which means they can be changed after >>>A1
creation. Each element of a list is assigned a number its [‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’]
position or index. The first index is 0, the second index is 1, >>>A = list(“PYTHON”)
the third index is 2 and so on. >>>A
[‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’]
Each element in the list has its definite place, which allows
>>>l = (‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’)
duplicating of elements in the list with each element having
its own distinct place and credibility. >>>l1 = list(l)
>>>l1
[‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’]
Creating a List
Or
In Python, lists can be created to put the elements in square
brackets [ ]. The elements in the list are separated by the list ( ) method is also used to create list of characters and
comma ( ,). integers through keyboard.
For example, For example,
>>> a= list(input (“Enter the elements :”))
a = [ 34 , 76 , 11 , 98 ]
Enter the elements : 234576
b = [‘s’, 3, 6, ‘t’] >>>a
c = [ 34 , 0. 5 , 75 ] [‘2’, ‘3’, ‘4’, ‘5’, ‘7’, ‘6’]
d =[ ] >>>b = list(input(“Enter string : ”))
Enter the string : ARIHANT
Creating a List From an Existing Sequence
>>>b
In Python, list ( ) method is used to create list from an
[‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’]
existing sequence.
2 CBSE Term II Computer Science XI

We can create different types of list in Python as follows: >>>l1 [0]


34
(i) Empty List
>>>l1 [6]
Empty list can be created in Python using [ ] . Here is the
76
two ways to create empty list as
>>>l1 [−4]
(a) >>>a = [ ]
‘Python’
>>>print (a)
>>>l1 [3]
Output
12
[]
>>>l1 [−3]
(b) >>>a = list ( )
11
>>>print (a) >>>l1 [9]
Output
It will give an error as IndexError: list index out of range.
[] Because it has 9 elements for which indexing are 0 to 8.
(ii) Mixed Data Types List
Difference between String and List
It can be created to place different data types such as
integers, strings, double etc., into one list. Strings are immutable which means the values provided to
them will not change in the program.
For example,
>>>a = [‘Neha’, ‘Sharma’, 25, 75, 6, 47]
a = “Here is string”
>>>print(a) You can extract value using index, find values but cannot
modify it.
Output
While lists are mutable which means the values of list can be
[‘Neha’, ‘Sharma’, 25, 75, 6, 47] changed at any point of time.
(iii) Nested List a = [1, 2, 3]
Nested lists are list objects where the elements in the lists You have some methods associated with lists like– append,
can be lists themselves. pop, extend etc.
For example, a [1 : 1 ] = [ 5 , 6 ], then ‘a’ will be [1, 5, 6, 2, 3].
>>> A = [‘Neha’, 4, 1, [5, 23, 4], 98]
>> print (A) Traversing a List
Output Traversing a list is a technique to access an individual
[‘Neha’, 4, 1, [5, 23, 4], 98] element of that list. It is also called iterate over a list.
List A contains 5 elements while inner list contains There are multiple ways to iterate over a list in Python.
3 elements ([5, 23, 4]). List A is considered [5, 23, 4] as one These are as follows
element.
Using for loop
Accessing Lists The most common and easy way to traverse a list is with for
loop. for loop is used when you want to traverse each
To access the list’s elements, index number is used. Use the element of a list.
index operator [ ] to access the elements of a list. The index Syntax for variable in list_name:
should be an integer. Index of 0 refers to first element, 1
refers to second element and so on. While the index of −1 For example,
refers to the first last element, −2 refers to the second last a = [‘P’, ‘R’, ‘O’, ‘G’, ‘R’, ‘A’, ‘M’]
element and so on. for i in a:
For example, print (i)
l1 = [5, 7, 3, 4, 5, 6, 9, 0, 8] Output
It is called positive index
P
0 1 2 3 4 5 6 7 8
R
5 7 3 4 5 6 9 0 8
O
–9 –8 –7 –6 –5 –4 –3 –2 –1
G
It is called negative index R
A
>>>l1 = [34, 87, ‘Computer’, 12, ‘Python’, 11, 76, M
‘Option’]
CBSE Term II Computer Science XI 3

Using for loop with range ( ) Greater than (>) operator


There is another method to traverse a list using for loop with It checks whether the left value is greater than that on the
range( ). This is also used len( ) function with range. This right.
method is used when you want to traverse particular For example,
characters in a list.
>>>a = [1, 2, 3, 4]
Syntax for variable in range (len(list_name)): >>>b = [5, 2, 3, 4]
For example,
>>>a > b
a = [‘P’, ‘R’, ‘O’, ‘G’, ‘R’, ‘A’, ‘M’]
False
for i in range (len (a)):
print (a [i]) It gives False, which get from first element from two lists as 1
Output > 5.
P
Less than or Equal to (<=) operator
R
O This operator returns True only, if the value on the left is
either less than or equal to that on the right of the operator.
G
R For example,
A >>>a = [2, 4, 3, 7]
M >>>b = [3, 4, 5, 7]
Program to display the elements of list >>>a <= b
True
[‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’]
in separate line with their index number. Greater than or Equal to (>=) operator
For example, This operator returns True only, if the value on the left is
list1 = [‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’] greater than or equal to that on the right of the operator.
L1 = len (list1)
For example,
for i in range (L1) :
>>>a = [4, 3, 6, 8]
print(“Element :”, list1 [i], “at index
number”, i) >>>b = [2, 5, 4, 3]
>>>a >= b
Output
True
Element : P at index number 0
Element : Y at index number 1 Equal to (= =) operator
Element : T at index number 2
This operator returns True, if the values on either side of the
Element : H at index number 3 operator are equal.
Element : O at index number 4
For example,
Element : N at index number 5
>>>a = [2, 3, 4, 6]
>>>b = [2, [3, 4], 6]
Comparison Operators >>>c = [2, 3, 4, 6]
A comparison operator in Python, also called Python >>>a = = b
relational operator (<, >, = =, ! = ,> = , <=) that compare
False
the values of two operands and returns True or False based
on whether the condition is met. >>>a = = c
True
Comparison operators for comparing lists are as follows

Less than (<) operator Not equal (! =) operator


This operator returns True, if the values on either side of the
It checks if the left value is lesser than that on the right.
operator are unequal.
For example,
For example,
>>>a = [1, 2, 3, 4]
>>>a = [2, 3, 4, 6]
>>>b = [5, 2, 3, 4]
>>>b = [2, [3, 4], 6]
>>>a < b
>>>a != b
True
True
It gives True, which get from first element from two lists as 1
< 5.
4 CBSE Term II Computer Science XI

Membership Operators >>>l


[43, 56, 34, 22, 34, 98]
These operators are used to find out whether a value is a The (+) operator cannot add list with other type as number
member of a sequence such as string, list, tuple, dictionary or string because this operator is used only with list types.
etc.
For example,
There are two types of membership operator as follows >>>l1 = [2, 5, 7]
>>>l = l1 + 5
in operator
Trackback (most recent call last) :
It evaluates True, if the value in the left operand appears in File “<pyshell#5>”, line 1, in <module>
the sequence found in the right operand. l = l1 + 5
For example, TypeError : can only concatenate list (not
l1 = [45, 76, [3, 98], 6] “int”) to list.
l2 = [60, [23, 43], 65]
For example,
for item in l1:
>>>l1 = [3, 2, 6]
if item in l2:
>>>l = l1 + “Try”
print (“Exist”)
else : Trackback (most recent call last):
print (“Not Exist”) File “<pyshell#1>”, line 1, in <module>
l = l1 + “Try”
Output TypeError : can only concatenate list (not
Not Exist “str”) to list.

not in operator Replicating List


It evaluates True, if the value in the left operand does not You can repeat the elements of the list using (*) operator.
appear in the sequence found in the right operand. This operator is used to replicate the list.
For example, Syntax list = list1 * digit
a = 54 For example,
b = 87 >>>l1 = [3, 2, 6 ]
list1 = [45, 65, 30, 78, 512, 87]
>>>l = l1 * 2
if (a not in list1):
>>>l
print (“a is NOT present in given list”) [3, 2, 6, 3, 2, 6]
else :
print (“a is present in given list”) Slicing of a List
if (b in list1): In Python list, there are multiple ways to print the whole list
print (“b is present in given list”) with all the elements, but to print a specific range of
else : elements from the list, we use slice operation. Slice operation
print (“b is NOT present in given list”) is performed on lists with the use of colon (:).
Output Syntax s = list_name [Start : End]
a is NOT present in given list For example,
b is present in given list >>>list1 = [4, 3, 7, 6, 4, 9, 5, 0, 3, 2]
>>>s = list1 [2 : 5]
List Operations >>>s
[7, 6, 4]
We can perform various operations on list in Python, some of To print elements from beginning to a range use [: Index], to
them are describe below print elements from end use [: –Index] and to print elements
Concatenate Lists from specific index till the end use [Index :].
The most conventional method to perform on the list For example,
concatenaton, the use of (+) operator can easily add the >>>list1 = [4, 3, 7, 6, 4, 9, 5, 0, 3, 2]
whole of one list to other list and hence perform the >>>s = list1 [: 5]
concatenation. >>>s
Syntax list = list1 + list2 [4, 3, 7, 6, 4]
For example, >>>s = list1 [: −6]
>>>l1 = [43, 56, 34] >>>s
>>>l2 = [22, 34, 98] [4, 3, 7, 6]
>>>l = l1 + l2 >>>s = list1 [3 :]
CBSE Term II Computer Science XI 5

>>>s For example,


[6, 4, 9, 5, 0, 3, 2] >>>l1 = [2, 4, “Try”, 54, “Again”]
You can also print all elements of list in reverse order using >>>l1 [0 : 1] = [34, “Hello”]
[: : −1]. >>>l1
For example, [34, ‘Hello’, 4, ‘Try’, 54, ‘Again’]
>>>s = list1 [: : −1] >>>l1 [4] = [“World”]
>>>s >>>l1
[2, 3, 0, 5, 9, 4, 6, 7, 3, 4] [34, ‘Hello’, 4, ‘Try’, [‘World’], ‘Again’]
Lists are also provide slice steps which used to extract >>>l1 [2] = “Hiiii”
elements from list that are not consecutive. >>>l1
Syntax s = list_name [Start : Stop : Step] [34, ‘Hello’, ‘Hiiii’, ‘Try’, [‘World’],
‘Again’]
It takes three parameters which are as follows
l
Start starting integer where the slicing of the object starts. Built-in Functions
l
Stop integer until which the slicing takes place. The slicing Python has large number of built-in functions and methods
stops at index −1. that make programming easier.
l
Step integer value which determines the increment Some of them are as follows
between each index for slicing.
For example,
(i) append ( )
>>>list1 = [4, 3, 7, 6, 4, 9, 5, 0, 3, 2] This method is used for appending and adding elements to a
>>>l1 = list1 [1 : 10 : 3] list. It is used to add elements to the last position of a list.
>>>l1 Syntax list_name.append (element)
[3, 4, 0] For example,
>>>l2 = list1 [2 : 12 : 2] >>>l1 = [34, 65, 23, 98]
>>>l2 >>>l1.append (76)
[7, 4, 5, 3] >>>l1
>>>l3 = list1 [::4] [34, 65, 23, 98, 76]
>>>l3
[4, 4, 3]
(ii) insert ( )
>>>l4 = list1 [::8] This method is used to insert an element at specified position
>>>l4 in the list. This method takes two arguments : one for index
[4, 3] number and second for element value.
>>>l5 = list1 [3 ::] Syntax list_name. insert (index, element)
>>>l5 For example,
[6, 4, 9, 5, 0, 3, 2] >>>l1 = [34, 65, 23, 98]
For example, >>>l1.insert (3, ‘New’)
>>>l1
Python program to count the number of elements in a given
[34, 65, 23, ‘New’, 98]
range using traversal and multiple line code.
c=0 (iii) extend ( )
l = 40
This method is used to add contents of list 2 to the end of list 1.
r = 80
list1 = [10, 20, 30, 40, 50, 40, 40, 60, 70] Syntax listname1. extend (list_name2)
for x in list1 : For example,
if x >= l and x <= r: >>>l1 = [43, ‘Hello’, 56]
c+ = 1 >>>l2 = [‘World’, ‘Try’, 65,77]
print(“List:”, list1) >>>l1.extend(l2)
print(“Elements in a list1:”, c) >>>l1
Output [43, ‘Hello’, 56, ‘World’, ‘Try’, 65, 77]
List : [10, 20, 30, 40, 50, 40, 40, 60, 70] (iv) sum ( )
Elements in a list1 : 6 This method is used to calculate the sum of all the elements
List Modification using Slicing in the list.
List can be modified after it created using slicing. Syntax sum (list_name)
6 CBSE Term II Computer Science XI

For example, It will return min value of character using ASCII value.
>>>l = [45, 23, 87, 5, 9] >>>l3 = [‘Rahul’, ‘Shiv’, ‘Sandhaya’, ‘Ankit’]
>>>sum (l) >>>min (l3)
169
‘Ankit’
sum ( ) method is used for only numeric values otherwise it
gives an error. (ix) max ( )
>>>l = [45, 23, 87, 5, ‘Hello’]
>>>sum (l)
It is used to return the maximum element out of elements of
list.
Trackback (most recent call last) :
File “<pyshell# 17>”, line 1, in <module> Syntax max (list_name)
sum(l) For example,
TypeError: unsupported operand type (s) for >>>l1 = [34, 76, 89, 33, 54, 65]
+ : ‘int’ and ‘str’ >>>max (l1)
89
(v) count ( ) >>>l2 = [‘t’, ‘e’, ‘E’, ‘U’, ‘v’]
This method is used to calculate total occurrence of given >>>max (l2)
element of list. ‘v’
Syntax list_name. count (element) It will return max value of character using ASCII value.
For example,
>>>list1 = [4, 3, 5, 2, 54, 4, 2, 6, 4, 4, 5]
(x) reverse ( )
>>>list1. count(4) Using the reverse ( ) method, we can reverse the contents of
4 the list object in-place, i.e. we don’t need to create a new list
instead we just copy the existing elements to the original list
(vi) len ( ) in reverse order.
This method is used to calculate the total length of list. Syntax list_name. reverse ( )
Syntax len (list_name) For example,
For example, >>>list1 = [34, 76, 89, 33, 54, 65]
>>>list1 = [4, 3, 5, 2, 54, 4, 2, 6, 4, 4, 5] >>>list1. reverse( )
>>>len (list1) >>>print (list1)
11 [65, 54, 33, 89, 76, 34]
>>>l = [‘Hii’, ‘Hello’, ‘Hey’, ‘Namesty’]
(vii) index () >>>l.reverse ( )
It returns the index of first occurrence. Start and end index >>>print (l)
are not necessary parameters. [‘Namesty’, ‘Hey’, ‘Hello’, ‘Hii’]
Syntax list_name.index (element[, start [, end]])
(xi) pop ( )
For example,
This function is used to remove the element and return last
>>>list1 = [3, ‘New’, 2, 6, ‘Hello’, 2]
value from the list or the given index value.
>>>list1.index (‘Hello’)
4
Syntax list_name.pop (index)
For example,
(viii) min ( ) >>>l1 = [34, 65, 22, 90, 87, 61]
It is used to return the minimum element out of elements of >>>l1.pop (3)
list. 90
Syntax min (list_name) >>>print (l1)
[34, 65, 22, 87, 61]
For example,
>>>l1 = [45, 87, 23, 90, 12] If you do not give any index value, then it will remove last
>>>min (l1) value from the list.
12 >>>l1. pop ( )
61
>>>l2 = [‘A’, ‘B’, ‘c’, ‘e’, ‘a’]
>>>print (l1)
>>>min (l2)
[34, 65, 22, 87]
‘A’
CBSE Term II Computer Science XI 7

(xii) remove ( ) (xiv) sort ()


This method searches for the given element in the list and This function is used to sort the given list in ascending order.
removes the first matching element. It takes a single element Syntax list _name. sort ( )
as an argument and remove it from the list.
For example,
Syntax list_name. remove (element) >>>list1 = [23, 65, 77, 23, 90, 99, 12]
For example, >>>list1. sort ( )
>>>list1 = [34, 76, 11, 98, 26, 20] >>>print (list1)
>>>list1.remove (11) [12, 23, 23, 65, 77, 90, 99]
>>>list1 >>>list2 = [‘abc’ ‘gdr’, ‘uyt’, ‘abc’,‘nki’]
[34, 76, 98, 26, 20] >>>list2. sort ( )
>>>l1 = [‘Maths’, ‘English’, ‘Hindi’, ‘History’, ‘Science’] >>>print (list2)
>>>l1.remove(‘History’) [‘abc’, ‘abc’, ‘gdr’, ‘nki’, ‘uyt’]
>>>l1 The sort function has an argument called
[‘Maths’, ‘English’, ‘Hindi’, ‘Science’]
reverse = True. This allows us to sort the list elements in
descending order.
If the element (argument) passed to the remove ( ) method
does not exist, ValueError exception is thrown. Syntax list _ name. sort (reverse = True)
>>>l1. remove ( ) For example,
Trackback (most recent call last) : >>>list1 = [23, 65, 77, 23, 90, 99, 12]
File “<pyshell# 11>”, line 1, in <module> >>>list1. sort (reverse = True)
>>>print (list1)
l1.remove ( )
[99, 90, 77, 65, 23, 23, 12]
TypeError : remove ( ) takes exactly one argument (0
given) (xv) list ()
(xiii) clear ( ) It takes sequence types and converts them to lists. This is
used to convert a given sequence (tuple/list/string) into list.
This function is used to remove all the items of a list. This
method will empty the entire list. Syntax list (seq)
For example,
Syntax list_name. clear ( )
>>>t1 = (‘Hello’, 34, 54, ‘xyz’)
For example, >>>list1 = list(t1)
>>>l1 = [23, 45, 87, 12, 98] >>>print (list1)
>>>l1.clear( ) [‘Hello’, 34, 54, ‘xyz’]
>>>l1 >>>t1 = ( )
[] >>>list1 = list (t1)
>>>print (list1)
[]
8 CBSE Term II Computer Science XI

Chapter
Practice
Ans. (c) insert () function is used to insert an element at specified
PART 1 position in the list. This method takes two arguments : one
for index number and second for element value.
Objective Questions Syntax list_name.insert(index, element)
6. Choose the correct option for the following.
l
Multiple Choice Questions l1 = [2, 5, 7]
1. Which value is used to represent the first index of l = l1 + 5
list? print (l)
(a) [7, 10, 12]
(a) 1 (b) 0
(b) [2, 5, 7, 5]
(c) −1 (d) a
(c) [5, 2, 5, 7]
Ans. (b) To access the list’s elements, index number is used. The
index number should be an integer. Index of 0 refers to first (d) TypeError
element, 1 refers to second element and so on. Ans. (d) + operator cannot add list with other type as number or
string because this operator is used only with list types.
2. Choose the output of following Python code. So, it will give TypeError as it can only concatenate list (not
1 = list () “int”) to list.
print ( 1)
(a) [] (b) ()
7. What is the output of following code?
l1 = [3, 2, 6]
(c) [,] (d) Empty
l = l1 * 2
Ans. (a) Empty list can be created in Python using []. To create
empty list, list () is also used.
print (l)
(a) [3, 2, 6, 3, 2, 6]
3. Suppose list (b) [6, 4, 12]
1 = [10, 20, 30, 40, 50, 60, 70] (c) [3, 4, 12]
print( 1[ −3]) (d) TypeError
(a) 30 (b) 50 Ans. (a) * operator can repeat the elements of the list.
(c) 40 (d) Error Syntax list = list1 * digit
Ans. (b) The index of −1 refers to the last element, −2 refers to the
8. Which of the following is true regarding lists in
second last element and so on. Hence, −3 refers to third last
element, i.e. 50.
Python?
(a) Lists are immutable.
4. Choose the output from following code. (b) Size of the lists must be specified before its initialisation.
list1 = [‘A’, ‘R’, ‘I’,‘H’,‘A’,‘N’,‘T’] (c) Elements of lists are stored in contiguous memory
print (list1 [7]) location.
(d) size(list1) command is used to find the size of lists.
(a) T (b) N
(c) A (d) Error Ans. (c) Elements of lists are stored in contiguous memory
location, so it is true regarding lists in Python.
Ans. (d) In the given code, we are trying to access 8th element
from the list which does not exist as we are having total 7 9. Suppose list1 is [56, 89, 75, 65, 99], what is the
elements for which the last index is 6. So, Python will give output of list1 [− 2]?
an IndexError. (a) Error (b) 75
5. Which function is used to insert an element at (c) 99 (d) 65
specified position in the list? Ans. (d) −1 corresponds to the last index in the list, −2 represents
(a) extend () (b) append () the second last element and so on.
So, the output for list1 [− 2] is 65 because 65 is second last
(c) insert () (d) add ()
element of list1.
CBSE Term II Computer Science XI 9

10. Identify the output of following code. 16. Which method will empty the entire list?
List1=[1, 2, 3, 7, 9] (a) pop() (b) clear()
(c) sort() (d) remove()
L=List1.pop(9)
Ans. (b) clear() method is used to remove all the items of a list.
print(L)
This method will empty the entire list.
(a) Syntax error (b) 9
Syntax
(c) [1, 2, 3, 7] (d) None of these
list_name.clear()
Ans. (a) In pop(9), parentheses put index number instead of
element. In the given list, maximum index number is 4, then 17. Which of the following allows us to sort the list
9 is out of index range. elements in descending order?
11. Suppose list1 is [2445,133,12454,123], what is the (a) reverse = True
output of max(list1)? (b) reverse = False
(a) 2445 (b) 133 (c) sort (descending)
(c) 12454 (d)123 (d) sort. descending
Ans. (c) max() returns the maximum element in the list. From Ans. (a) sort() is used to sort the given list in ascending order. The
given options, 12454 is the element with maximum value. sort() has an argument called reverse = True. This allows us
to sort the list elements in descending order.
12. To add a new element to a list, which command will
we use? 18. Identify the correct output.
(a) list1.add(8) >>>l1 = [34, 65, 23, 98]
(b) list1.append(8) >>>l1. insert(2, 55)
(c) list1.addLast(8) >>> l1
(a) [34, 65, 23, 55] (b) [34, 55, 65, 23, 98]
(d) list1.addEnd(8)
(c) [34, 65, 55, 98] (d) [34, 65, 55, 23, 98]
Ans. (b) We use the function append() to add an element to the
Ans. (d) insert() is used to insert an element at specified position
list.
in the list. This method takes two arguments : one for index
13. What will be the output of the following Python number and second for element value.
code? Syntax
list1=[9, 5, 3, 5, 4] list_name.insert(index, element)
list1[1:2]=[7,8] 19. Find the output from the following code.
print(list1) list1=[2, 5, 4, 7, 7, 7, 8, 90]
(a) [9,5, 3, 7, 8] (b) [9, 7, 8, 3, 5, 4] del list1[2 : 4]
(c) [9,[ 7, 8], 3, 5,4] (d) Error print(list1)
Ans. (b) In the piece of code, slice assignment has been (a) [2, 5, 7, 7, 8, 90] (b) [5, 7, 7, 7, 8, 90]
implemented. The sliced list is replaced by the assigned (c) [2, 5, 4, 8, 90] (d) Error
elements in the list. Ans. (a) del keyword is used to delete the elements from the list.
14. Consider the declaration a=[2, 3, ‘Hello’, 23.0]. 20. Slice operation is performed on lists with the use of
Which of the following represents the data type of (a) semicolon (b) comma
‘a’? (c) colon (d) hash
(a) String (b) Tuple Ans. (c) In Python list, there are multiple ways to print the whole
(c) Dictionary (d) List list with all the elements, but to print a specific range of
Ans. (d) List contains a sequence of heterogeneous elements elements from the list, we use slice operation. Slice
which store integer, string as well as object. It can created to operation is performed on lists with the use of colon (:).
put elements separated by comma (,) in square brackets [].
15. Identify the output of the following Python
l
Case Based MCQs
statement. 21. Suppose that list L1
x = [[1, 2, 3, 4], [5, 6, 7, 8]] [“Hello”, [“am”, “an”], [“that”, “the”, “this”], “you”,
y = x [0] [2] “we”, “those”, “these”]
print(y) Based on the above information, answer the
(a) 3 (b) 4 following questions.
(c) 6 (d) 7
(i) Find the output of len (L1).
Ans. (a) x is a list, which has two sub-lists in it. Elements of first
(a) 10 (b) 7
list will be represented by [0] [i] and elements of second list
will be represented by [1] [i]. (c) 6 (d) Error
10 CBSE Term II Computer Science XI

(ii) Find the output of L1[3 : 5]. 2. list1 = [45, 77, 87, ‘Next’, ‘Try’, 33, 43]
(a) [“that”, “the”, “this”] (b) [“we”, “those”] Observe the given list and find the answer of
(c) [“you”, “we”] (d) [you, we] questions that follows.
(iii) What will be the output of L1[5:] +L1[2]? (i) list1[−2] (ii) list1[2]
(a) [‘those’, ‘these’, ‘that’, ‘the’, ‘this’] Ans. (i) 33 (ii) 87
(b) [‘those’, ‘these’]
3. Distinguish between string and list.
(c) [‘that’, ‘the’, ‘this’]
Ans. Strings are immutable, which means the values provided to
(d) Error
them will not change in the program. While lists are
(iv) Choose the correct output of mutable which means the values of list can be changed at
print (L1[6:]) any point of time in program.
(a)“those” (b) “these” 4. What is the output of below questions?
(c) “those”, “these” (d) None of these l2 = [75, 43, 40, 36, 28, 82]
(v) Give the correct statement for (i) l2.sort ( )
[‘Hello’, [‘am’, ‘an’], [‘that’, ‘the’, ‘this’], ‘you’, ‘we’, (ii) l2.sort (reverse = True)
‘those’, ‘these’] Ans. (i) [28, 36, 40, 43, 75, 82]
(a) L1[] (b) L1[:] (ii) [82, 75, 43, 40, 36, 28]

(c) all.L1() (d) L1(all) 5. Find the errors.


Ans. (i) (b) len() is used to calculate total occurrence of L1 = [2, 4, 5, 9]
given element of list. L1 is a nested list which contains L2 = L1 * 3
two sub-lists and a sub-list is considered as a single L3 = L1 + 3
element. L4 = L1. pop (5)
(ii) (c) To print a specific range of elements from the list, we Ans. Error 1 L3 = L1 + 3 because + operator cannot add list
use slice operation. Slice operation is performed on lists with other type as number or string.
with the use of colon (:). In L1[3 : 5], slicing start from Error 2 L1.pop (5) parentheses puts index value instead of
index number 3, i.e. ‘you’ to index number (5 − 1) ⇒ 4 i.e. element. In the given list, maximum index value is 3 and 5 is
‘we’. out of index range.
(iii) (a) To print elements from specific index till the end, use
[Index:], so L1[5:] will print from index number 5 till end. 6. What will be the output of the following Python
i.e. ‘those’, ‘these’. To print the element at specified code?
index number use [index_number], so L1[2] will print the a=[13,6,77]
element at index number 2 which is a sub-list and a.append([87])
considered as single element i.e. ‘that’, ‘the’, ‘this’.
a.extend([45,67])
+ operator is used to concatenate the element of list.
print(a)
(iv) (b) To print elements from specific index till the end, use
[Index :], so L1[6:] will print from index number 6 till end Ans. [13,6,77, [87], 45, 67]
i.e. “these”. 7. What will be the output of the following Python
(v) (b) To print the whole list, use [:], so L1[:] will print the
entire list.
code?
a=[18,23,69,[73]]
b=list(a)
PART 2 a[3][0]=110
a[1]=34
Subjective Questions print(b)
Ans. [18, 23, 69, [110]]
l
Short Answer Type Questions 8. Predict the output.
L2 = [4, 5, 3, 1]
1. What is nested list ? Explain with an example. L3 = [3, 4, 11, 2]
Ans. Nested lists are list objects where the elements in the lists
(i) print (L2 + L3)
can be lists themselves.
For example, (ii) print (L2. count (0))
list1=[45,43,12,‘Math’,‘Eng’,[75,34,
(iii) print (L3 [4])
‘A’],5] (iv) L3. remove (11)
Here, list1 contains 7 elements, while inner list contains print (L3)
3 elements. list1 is considered [75, 34, ‘A’] as one element. Ans. (i) [4, 5, 3, 1, 3, 4, 11, 2] (ii) 0
(iii) IndexError (iv) [3, 4, 2]
CBSE Term II Computer Science XI 11

9. Find the output. (ii) Returns the index of first occurrence.


L = [3, 4, 53, 4, 0, 2, 4, 7, 29] (iii) Adds contents of list2 to the end of list1.
(i) L [2 : 5] (ii) L [: 7] Ans. (i) append ( ) (ii) index ( )
(iii) L [4 :] (iv) [: : −1] (iii) extend ( )
Ans. (i) [53, 4, 0] (ii) [3, 4, 53, 4, 0, 2, 4] 15. Consider the following list myList. What will be
(iii) [0, 2, 4, 7, 29] (iv) [29, 7, 4, 2, 0, 4, 53, 4, 3] the elements of myList after the following two
10. Find the output of the given code. operations:
list2 = [‘A’,‘R’,‘I’,‘H’,‘A’,‘N’,‘T’] myList = [10,20,30,40]
for i in range (len (list2)): (i) myList.append([50,60])
print (list2 [i]) (ii) myList.extend([80,90]) [NCERT]
Ans. A Ans. (i) [10, 20, 30, 40, [50, 60]]
R (ii) [10, 20, 30, 40, 80, 90]
I
H
16. What will be the output of the following code
segment?
A
N myList = [1,2,3,4,5,6,7,8,9,10]
T for i in range(0,len(myList)):
if i%2 == 0:
11. Define the replicating lists with an example. print(myList[i]) [NCERT]
Ans. In Python, you can repeat the elements of the list using (*) Ans. 1
operator. This operator is used to replicate the list.
3
For example,
>>>l1 = [4, 5, 7, 1] 5
>>>l2 = l1 * 2 7
>>>l2 9
[4, 5, 7, 1, 4, 5, 7, 1] 17. What will be the output of the following code
12. Consider the following list and answer the below segment?
questions. (i) myList = [1,2,3,4,5,6,7,8,9,10]
del myList[3:]
l1 = [89, 45, “Taj”, “Qutub”, 93, 42, “Minar”, “Delhi”,
“Agra”] print(myList)

(i) l1 [5 :] (ii) “Qutab” not in l1 (ii) myList = [1,2,3,4,5,6,7,8,9,10]


del myList[:5]
(iii) l1 [−3] (iv) l1 [9] print(myList)
(v) l1[2 : 5] (vi) l1[–2 : 5] (iii) myList = [1,2,3,4,5,6,7,8,9,10]
Ans. (i) [42, ‘Minar’, ‘Delhi’, ‘Agra’] del myList[::2]
(ii) False print(myList) [NCERT]
(iii) ‘Minar’
Ans. (i) [1, 2, 3]
(iv) It gives IndexError because there is index value 0 to 8. (ii) [6, 7, 8, 9, 10]
(v) [‘Taj’, ‘Qutub’, 93] (iii) [2, 4, 6, 8, 10]
(vi) []
18. Differentiate between append() and extend()
13. Predict the output. functions of list. [NCERT]
L1 = [3, 4, 5, 9, 11, 2, 27] Ans. Differences between append() and extend() functions of list
print (L1. index (3)) are
print (max (L1)) append() extend()
print (len (L1)) append() method adds an extend() method concatenates
Ans. Output element to a list. the first list with another list
(or another iterable).
0
27 When append() method adds extend() method iterates over
7 its argument as a single its argument adding each
element to the end of a list, element to the list, extending
14. Write the suitable method’s name for the below the length of the list itself the list.
conditions. will increase by one.
(i) Adds an element in the end of list.
12 CBSE Term II Computer Science XI

19. Consider a list: Output


list1 = [6,7,8,9] List after pushing all zeroes to end of list :
[4, 7, 9, 8, 2, 4, 9, 0, 0, 0, 0]
What is the difference between the following
operations on list1? 23. Observe the following list and answer the questions
(i) list1 * 2 that follows.
(ii) list1 *= 2 l1 = [45, 65,“The”, [65, “She”, “He”], 90, 12, “This”, 21]
(iii) list1 = list1 * 2 [NCERT] (i) l1 [3 : 4] = [“That”, 54]
Ans. (i) The statement will print the elements of the list twice, (ii) [l1 [4]]
i.e. [6, 7, 8, 9, 6, 7, 8, 9]. However, list1 will not be altered.
(ii) This statement will change the list1 and assign the list (iii) l1 [:7]
with repeated elements, i.e. [6, 7, 8, 9, 6, 7, 8, 9] to list1. (iv) l1 [1 : 2] + l1 [3 : 4]
(iii) This statement will also have same result as the statement Ans. (i) [45, 65, ‘The’, ‘That’, 54, 90, 12, ‘This’, 21]
‘list1 *= 2’. The list with repeated elements, i.e. [6, 7, 8,
(ii) [54]
9, 6, 7, 8, 9] will be assigned to list1.
(iii) [45, 65, ‘The’, ‘That’, 54, 90, 12]
20. What possible output(s) are expected to be (iv) [65, ‘That’]
displayed on screen at the time of execution of the
program from the following code? 24. Write a Python program to find the third largest
number in a entered list.
List = [“Poem”, “Book”, “Pencil”, “Pen”]
y=[]
List1 = List [2 : 3] num = int(input(“Enter number of elements:”))
List[2] = “Scale” for i in range (1, num + 1):
print (List1) x = int (input (“Enter element:”))
Ans. [“Pencil”] y.append(x)
y. sort ()
l
Long Answer Type Questions print(“Third largest element is :”, y[num-3])
Output
21. Write the best suited method’s name for the Enter number of elements : 5
following conditions. Enter element : 76
(i) Insert an element at specified position. Enter element : 45
(ii) Add contents from one list to other. Enter element : 98
(iii) Calculate the total length of list. Enter element : 90
Enter element : 23
(iv) Reverse the contents of the list object.
Third largest element is : 76
Ans. (i) insert ( )
(ii) extend ( ) 25. Write Python program to display all the common
(iii) len ( ) elements of two lists.
(iv) reverse ( ) list1 = [ ]
num = int (input (“Enter number of elements in List1
22. Write a program to move all zeroes to the end of :”))
the list.
for i in range (1, num +1):
list1 = [4, 7, 0, 9, 8, 0, 2, 0, 4, 9, 0] x = int (input(“Enter element:”))
n = len (list1) list1. append (x)
count = 0 list2 = [ ]
for i in range (n): num1 = int (input (“Enter number of elements in List2
if list1[i] ! = 0: :”))
list1 [count] = list1[i] for j in range (1, num1 +1):
count + = 1 y = int (input (“Enter element:”))
while count < n : list2. append (y)
list1 [count] = 0
a_set = set (list1)
count + = 1
b_set = set (list2)
print (“List after pushing all zeroes to if (a_set & b_set):
end of list:”) print (“Common elements are:”, a_set &
print (list1) b_set)
CBSE Term II Computer Science XI 13

else : (iv) print(stRecord[1])


print (“No common elements”) (v) stRecord[0]=‘Raghav’
Output
28. Write a program to read a list of n integers (positive
Enter number of elements in List1:5
as well as negative). Create two new lists, one
Enter element : 23
having all positive numbers and the other having
Enter element : –45 all negative numbers from the given list. Print all
Enter element : 84 three lists. [NCERT]
Enter element : –12
Ans. List = []
Enter element : 33 Pos = []
Enter number of elements in List2:5 Neg = []
Enter element : 12 Num = int(input(“Enter the Total Number of
Enter element : –45 List Elements : ”))
Enter element : –65 for i in range(1, Num + 1):
Enter element : 41 value = int(input(“Enter the Value of
Enter element : 32 %d Element : ” %i))
Common elements are : {–45} List.append(value)
26. What will be the output of the following for j in range(Num):
statements? if(List[j] >= 0):
Pos.append(List[j])
(i) list1 = [12,32,65,26,80,10]
else:
list1.sort() Neg.append(List[j])
print(list1) print(“Element in Positive List is : ”,
(ii) list1 = [12,32,65,26,80,10] Pos)
sorted(list1) print(“Element in Negative List is : ”,
Neg)
print(list1)
(iii) list1 = [1,2,3,4,5,6,7,8,9,10] 29. Write a program to read a list of n integers and find
their median.
list1[::−2]
Note The median value of a list of values is the middle
list1[:3] + list1[3:] one when they are arranged in order. If there are two
(iv) list1 = [1,2,3,4,5] middle values then take their average. [NCERT]
list1[len(list1)−1] [NCERT] Hint You can use a built-in function to sort the list.
Ans. (i) [10, 12, 26, 32, 65, 80] Ans. num = int(input(“Enter the number of
(ii) [12, 32, 65, 26, 80, 10] elements : ”))
(iii) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] list1 = list()
(iv) 5
for i in range(num):
27. The record of a student (Name, Roll No., Marks in x = int(input(“Enter the integer: ”))
five subjects and percentage of marks) is stored in list1.append(x)
the following list: print(“Original list:”,list1)
stRecord = [‘Raman’,‘A-36’,[56,98,99,72,69], 78.8]
list1.sort()
Write Python statements to retrieve the following print(“Sorted list: ”,list1)
information from the list stRecord. c = len(list1)
(i) Percentage of the student if c%2 != 0:
(ii) Marks in the fifth subject med = c//2
(iii) Maximum marks of the student print(“Median: ”,list1[med])
(iv) Roll No. of the student else:
a = list1[c//2]
(v) Change the name of the student from ‘Raman’ to
‘Raghav’ [NCERT] b = list1[(c//2) − 1]
Ans. s=a+b
(i) print(stRecord[3])
med = s/2
(ii) print(stRecord[2][4])
print(“Median: ”, med)
(iii) print(max(stRecord[2]))
14 CBSE Term II Computer Science XI

30. Write a program to read a list of elements. Modify x = int(input(“Enter the element:
this list, so that it does not contain any duplicate ”))
elements, i.e. all elements occurring multiple times list1.append(x)
in the list should appear only once. [NCERT] print(“Original list: ”,list1)
Ans. list1=[] print()
num=int(input(“Enter the number of pos = int(input(“Enter the position of
elements: ”)) the element you want to delete: ”))
for i in range(num): del list1[pos]
x=int(input(“Enter the element: ”)) print(“List after deletion:”,list1)
list1.append(x) (ii) num = int(input(“Enter the number of elements: ”))
print(“New list: ”) list1 = list()
print(list(set(list1))) for i in range(num):
x = int(input(“Enter the element:
31. Write a program to read a list of elements. Input an
”))
element from the user that has to be inserted in the
list1.append(x)
list. Also, input the position at which it is to be
print(“Original list: ”,list1)
inserted. Write a user defined function to insert the
x = int(input(“Enter the element you
element at the desired position in the list. [NCERT]
want to delete: ”))
Ans. num = int(input(“Enter the number of elements: ”))
list1.remove(x)
list1 = list()
print(“List after deletion: ”,list1)
for i in range(num):
x = int(input(“Enter the element: ”)) 33. In Python, list is a type of container in data
list1.append(x) structures, which is used to store multiple data at
print(“Original list: ”,list1) the same time. It can store integer, string as well as
print() object in a single list. Lists are mutable which
pos = int(input(“Enter the index means they can be changed after creation. Each
position: ”)) element of a list is assigned a number its position or
ele = int(input(“Enter the new element: ”)) index. The first index is 0, the second index is 1, the
list1.insert(pos, ele) third index is 2 and so on.
print() Based on the above information, answer the
print(“New list: ”,list1) following questions.
32. Write a program to read elements of a list. (i) List is defined by which type of bracket?
(i) The program should ask for the position of the (ii) List contains a sequence of what type of
element to be deleted from the list. Write a elements?
function to delete the element at the desired (iii) Lists are mutable. What is it mean?
position in the list. (iv) Which method is also used to create list of
(ii) The program should ask for the value of the characters and integers through keyboard?
element to be deleted from the list. Write a (v) How to represent the first index of list?
function to delete the element of this value from Ans. (i) []
the list. [NCERT] (ii) Heterogeneous
Ans. (i) num = int(input(“Enter the number of (iii) Lists are mutable, which means they can be changed
elements: ”)) after creation
list1 = list() (iv) list ()
for i in range(num): (v) 0
Chapter Test
Multiple Choice Questions 8. What will be the output of following code?
1. What is the output of following code? l = []
list1=[4, 3, 7, 6, 4, 9, 5, 0, 3, 2] for i in range (20, 40) :
l1=list1[1:10:3] if(i % 7 == 0 ) and (i % 5 ! = 0 ) :
print(l1) l . append (str(i))
(a) [3, 7, 6] (b) [3, 4, 0] print (‘.’. join(l))
(c) [3, 6, 9] (d) [7, 9,2] 9. What are the output of below questions?
2. Identify the output of following Python statement. L = [45, 89, 74, 12, 9, 83]
a = [[0, 1, 2], [3, 4, 5, 6]] (i) L.remove ()
b = a [1] [2] (ii) L.remove (12)
print (b)
(a) 2 (b) 1 (c) 4 (d) 5
10. Predict the output.
L1 = [3, 2, 1]
3. Identify the output of following code. L2 = [5, 9, 8]
list1 = [2, 3, 9, 12, 4]
(i) L1 * L2
list1.insert(4, 17)
(ii) L2.sort ( )
list1.insert(2, 23)
print(list1 [−4]) (iii) L1.reverse ( )
(a) 4 (b) 9 (c) 12 (d) 23 11. Write a program to input a list and print it in reverse
4. What will be the output of the following Python code? order.
books = [‘Hindi’, ‘English’, ‘Computer’] 12. Give the output.
if ‘put’ in books: (i) str1 = ‘aeiou’
print(True) list1 = list(str1)
else: print(list1)
print(False)
(ii) list1 = [2, 3, 4, 5]
(a) True (b) False (c) None (d) Error
list1. append(1)
5. Identify the output of the following Python statement. print(list1)
list1=[4,3,7,9,15,0,3,2]
s = list1[2:5] Long Answer Type Questions
print(s) 13. Write the best suited method’s name for the following
(a) [7,9,15,0] (b) [3,7,9,15] conditions.
(c) [7,9,15] (d) [7,9,15,0,3]
(i) Remove the value from the list.
6. What will be the output of following code? (ii) Sort the elements in descending order.
list1=[2, 5, 4, [9, 6], 3] (iii) Calculate the sum of all the elements of list.
list1[3][2] =10
(iv) Return the minimum element out of elements.
print(list1)
(a) [2, 5, 4, [9, 10], 3] (b) [2, 5, 4, 10, [9, 6], 3]
14. Write program to find the minimum and maximum
elements from the entered list.
(c) Index out of range (d) None of these
15. Write program to calculate the sum and mean of the
Short Answer Type Questions elements which are entered by user.
7. What will be the output of the following Python code? 16. Write program to count the frequency of elements in a
list1 = [11, 12, 13, 14, 15] list entered by user.
for i in range (1, 5) :
17. Write program to search for an element with its
list1[i−1] = list1[i] respective index number.
for i in range (0, 5) :
18. Write program to enter the elements of a list and
print(list1[i],end = “ ”) reverse these elements.

Answers For Detailed Solutions


Multiple Choice Questions Scan the code
1. (b) 2. (d) 3. (b) 4. (b) 5. (c) 6. (c)
16 CBSE Term II Computer Science XI

CHAPTER 02

Tuples
In this Chapter...
l Tuple vs List l Comparing Tuples

l Creating a Tuple in Python l Membership Operators

l Accessing Tuples l Common Tuple Operations

l Traversing a Tuple l Deleting a Tuple

A tuple is a collection of Python objects separated by commas Here is the two ways to create empty tuple as
(,) and put the elements in parentheses. Tuples are >>>t = ()
immutable by design which means they cannot be changed >>>print (t)
after creation. Tuple holds a sequence of heterogeneous ()
elements. Tuples store a fixed set of elements and do not >>>t = tuple ()
allow changes. >>>print(t)
()

Tuple vs List Single Element Tuple


l
Elements of a tuple are immutable whereas elements of a Creating a single element tuple is very complicated because
list are mutable. it considered as integer value, if you give single element in a
l
Tuples are declared in parentheses ( ), while lists are tuple.
>>>t=(8)
declared in square brackets [ ]. >>>t
l
Iterating over the elements of a tuple is faster compared to 8
iterating over a list. >>>t=(“a”)
>>>t
‘a’
Creating a Tuple in Python
For creating a single element tuple, you have to put comma
To create a tuple in Python, put all the elements in a (,) after the element.
parentheses ( ), separated by commas. We can have tuple of >>>t = 8,
same type of data items as well as mixed type of data items. >>>t
a = (34, 76, 12, 90) (8,)
b = (‘s’, 3, 6, ‘a’) >>>t1 = (5,)
c = (34, 0.5, 75) >>>t1
d = () (5,)
>>>t2=(“a”,)
We can create different types of tuple in Python, which are
>>>t2
as follows:
(‘a’,)
Empty Tuple
Nested Tuple
Empty tuple can be created in Python using ( ). It takes the
truth value as false or equivalent of 0. Nested tuples are tuple objects where the elements in the
tuples can be tuples themselves.
CBSE Term II Computer Science XI 17

For example, For example,


>>>t=(9, 6, 9, (1, 4, 8), 7) t1 = (87, 90, ‘Maths’, ‘English’, 56, 44, 99, ‘Science’, 23)
>>>print(t) >>>t1[1]
(9, 6, 9, (1, 4, 8), 7) 90
It contains 5 elements while inner tuple contains 3 elements >>>t1[− 2]
as (1, 4, 8). Tuple will considered (1, 4, 8) as one element. ‘Science’ It is called positive index
>>>t1[7] 0 1 2 3 4 5 6 7 8
Mixed Data Types Tuple ‘Science’ 87 90 'Maths' 'English' 56 44 99 'Science' 23
It can be created to place different data types such as >>>t1[4] –9 –8 –7 –6 –5 –4 –3 –2 –1
integers, strings, double etc, into one tuple.
56 It is called negative index
For example, >>>t1[−3]
>>>t1=(‘Maths’, 90, 89, ‘English’, 78.5)
99
>>>t1
(‘Maths’, 90, 89, ‘English’, 78.5) If we give index value out of range, then it will give error
>>>t1[9]
Creating Tuple from an Existing Sequence Trackback (most recent call last) :
In Python, tuple( ) method is used to create tuple from an File “<pyshell#8>”, line 1, in <module>
existing sequence. t1[9]
Syntax new_tuple_name = tuple (sequence) IndexError : tuple index out of range.
Here is the sequence includes list, string, tuple etc. If you give index number with decimal point, it will also give
For example, error
>>>t=“PROGRAM” >>>t1[4.5]
>>>t1=tuple(t) Trackback(most recent call last):
>>>t1 File“<pyshell#9>”, line1, in <module>
(‘P’, ‘R’, ‘O’, ‘G’, ‘R’, ‘A’, ‘M’) t1[4.5]
>>>t=tuple(“PROGRAM”) TypeError: tuple indices must be integers or slices, not float.
>>>t
(‘P’, ‘R’, ‘O’, ‘G’, ‘R’, ‘A’, ‘M’) Traversing a Tuple
>>>t1=[‘P’, ‘R’, ‘O’, ‘G’, ‘R’, ‘A’, ‘M’]
>>>t2=tuple(t1) Traversing a tuple is a technique to access an individual
>>>t2
element of that tuple. It is also called iterate over a tuple.
(‘P’, ‘R’, ‘O’, ‘G’, ‘R’, ‘A’, ‘M’) There are multiple ways to iterate over a tuple in Python.
tuple ( ) method is also used to create tuple of characters and These are as follows:
integers which entered through keyboard.
Using for loop
For example,
>>>t=tuple (input(“Enter the elements:”)) The most common and easy way to traverse a tuple is with for
Enter the elements : 24567
loop. This method is used when you want to iterate all
elements of a tuple.
>>>t
(‘2’, ‘4’, ‘5’, ‘6’, ‘7’) Syntax for variable in tuple_name :
>>>b=tuple(input(“Enter string :”)) For example,
Enter string : PUBLICATION t=(‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’)
>>>b for i in t :
(‘P’, ‘U’, ‘B’, ‘L’, ‘I’, ‘C’, ‘A’, ‘T’, ‘I’, ‘O’, ‘N’) print(i)
Output
Accessing Tuples P
To access the tuple’s elements, index number is used. Tuples Y
are accessed similar of list except for the mutability. Use the T
index operator [ ], elements of a tuple can be access. The H
index should be an integer. Index of 0 refers to first element,
O
1 refers to second element and so on. While the index of − 1
refers to the last element, − 2 refers to the second last N
element and so on.
18 CBSE Term II Computer Science XI

Using for loop with range ( ) Operators Description Example


Greater It returns True only if the >>>a=(4, 7, 2)
There is another method to traverse a tuple using for loop
than or value on the left is greater >>>b=(2,(6,7), 4)
with range ( ). This is also used len() function with range. Equal to than or equal to that on >>>a>=b
This method is used when you want to iterate specified (>=) the right of the operator. True
elements of a tuple. Equal to It returns True if the >>>a=(1,(2,3), 4)
Syntax for index in range(len(tuple_name)): (= =) values on either side of >>>b=(1,2,3,4)
For example, the operator are equal. >>>a==b
False
t=(‘P’, ‘Y’, ‘T’, ‘H’, ‘O’, ‘N’)
for i in range (len(t)): Not equal It returns True if the >>>a=(6, 7, 5)
to (!=) values on either side of >>>b=(6, 4, 2)
print(t[i])
the operator are unequal. >>>a!=b
Output True
P
Y
T
Membership Operators
H These operators are used to check whether a value/variable
exists in the tuples. These operators return True or False as
O
per the conditions met.
N
Membership operators in Python are two types as follows
e.g. Program to display the elements of tuple (‘A’, ‘R’, ‘I’, ‘H’,
‘A’, ‘N’, ‘T’) in separate line with their index number. in Operator
tuple1=(‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’)
This operator is used to check if a value exists in a sequence
l=len(tuple1) or not. If it exists in the sequence, then it will return True
for i in range (l): else it will return False.
print(“Character:”, tuple1[i], For example,
“at index number:”, i) tuple1=(1,2,3,4,5)
Output tuple2=(6,7,8,9)
Character : A at index number : 0 for item in tuple1:
Character : R at index number : 1 if item in tuple2:
Character : I at index number : 2 print(“overlapping”)
Character : H at index number : 3 else:
Character : A at index number : 4 print(“not overlapping”)
Character : N at index number : 5 Output
Character : T at index number : 6 not overlapping

Comparing Tuples not in Operator


A comparison operator in Python is also called Python This operator is the opposite of ‘in’ operator. So, if a value
relational operator (<, >, = = , ! =, > =, < =) that does not exist in the sequence then it will return a True else
compares the values of two operands and returns True or it will return a False.
False based on whether the condition is met. For example,
Comparison operators for comparing tuples are as follows x=44
Operators Description Example y=30
tuple = (45, 65, 30, 78, 512)
Less than It checks if the left value
>>>a=(3, 5, 2, 7)
(<) is lesser than that on the if(x not in tuple):
>>>b=(3, 7, 0, 2)
right. >>>a<b print(“x is NOT present in given tuple”)
True else :
Greater It checks if the left value >>>a=(4, 7, 2, 8) print (“x is present in given tuple”)
than (>) is greater than that on the >>>b=(3, 7, (2), 8) if(y in tuple):
right. >>>a>b print(“y is present in given tuple”)
True else:
Less than It returns True only if the >>>a=(0, 5, 1, 2) print(“y is NOT present in given tuple”)
or Equal to value on the left is either >>>b=(3, 4, 2, 5) Output
(<=) less than or equal to that >>>b<=a
on the right of the x is NOT present in given tuple
operator. False y is present in given tuple
CBSE Term II Computer Science XI 19

Common Tuple Operations Tuple Slicing


In Python, there are multiple ways to display the tuple with
We can perform various operations on tuple in Python. Some all elements, but to display a specific range of elements from
of them are describe below: the tuple, we use slicing operation. This operation is
performed on tuples with the use of colon (:).
Concatenate Tuples Syntax tuple_name [Start:Stop]
To concatenate tuples, (+) operator is used in Python. This For example,
operator can easily add the whole of one tuple to other tuple >>>tuple1=(4, 7, 3, “This”, 6, “That”, “These”, 8, 9,
and perform concatenation. “Those”)
For example, >>>t1=tuple1 [3:6]
>>>t1=(45, 65, 23, 9) >>>t1
>>>t2=(34, 23, 65) (‘This’, 6, ‘That’)
>>>t=t1+t2 To display elements from beginning to a range use [: index],
>>>t to display elements from end use [:-index] and to display
elements from specific index till the end use [Index :]
(45, 65, 23, 9, 34, 23, 65)
For example,
Concatenate operator (+) cannot add one tuple with other
>>>tuple1=(4, 7, 3, “This”, 6,“That”,“These”, 8,9,“Those”)
type as number or string. It will give error in such conditions. >>>t2=tuple1[:6]
For example, >>>t2
>>>t1=(5, 3, 8, 3) (4, 7, 3, ‘This’, 6, ‘That’)
>>>t3=tuple1[:-4]
>>>t=t1+4
>>>t3
Trackback (most recent call last): (4, 7, 3, ‘This’, 6, ‘That’)
File “<pyshell # 5>”, line1, in <module> >>>t4=tuple1[-4:]
t=t1+4 >>>t4
TypeError : can only concatenate tuple (not “int”) to tuple (‘These’, 8, 9, ‘Those’)
>>>t1=(4,5,3) >>>t5=tuple1[7:]
>>>t = t1 + “Hello” >>>t5
(8, 9, ‘Those’)
Trackback (most recent call last):
>>>t=(4,5,(3,7,5),9,2)
File “<pyshell#6>”, line1, in <module> >>>t1=t[2:5]
t = t1 + “Hello” >>>t1
TypeError: can only concatenate tuple (not “str”) to tuple ((3, 7, 5), 9, 2)
>>>t2=t[4:-2]
Replicate Tuple >>>t2
You can repeat the elements of the tuple using ( *) operator. ()
This operator is used to replicate the tuple. We can also print all elements of tuple in reverse order using
[::-1]
For example,
>>>t=tuple1[::-1]
>>>t1=(4, 6, 2, 8) >>>t
>>>t=t1*3 (‘Those’, 9, 8, ‘These’, ‘That’, 6, ‘This’, 3, 7, 4)
>>>t >>>t=tuple1[2:-4]
(4, 6, 2, 8, 4, 6, 2, 8, 4, 6, 2, 8) >>>t
(3, ‘This’, 6, ‘That’)
This operator cannot multiply two tuples.
>>>t1=(4, 5, 3) Tuples are also provide slice steps which used to extract
>>>t2=(5, 0, 8)
elements from tuple that are not consecutive.
>>>t=t1*t2 Syntax t=tuple_name[Start : Stop : Step]
Trackback (most recent call last): Here,
File “<pyshell#11>”, line 1 , in <module> l
Start integer where the slicing of the object starts.
t=t1*t2 l
Stop integer until which the slicing takes place. The slicing
TypeError : can’t multiply sequence by non-int of type stops at index stop-1.
'tuple'. l
Step integer value which determines the increment
between each index for slicing.
20 CBSE Term II Computer Science XI

For example, (ii) count()


>>>t=(5, 3, “He”,“She”, (4, 3, “It”),3,“They”, 8,9 “We”)
This function is used to calculate total occurrence of given
>>>t1=t[2:8:2]
element of tuple.
>>>t1
(‘He’, (4, 3, ‘It’), ‘They’) Syntax tuple_name.count(element)
>>>t2=t[::3] For example,
>>>t2 >>>t1=(10, 20, 30, 40, 10, 50, 20, 60, 10)
(5, ‘She’, ‘They’, ‘We’) >>>t1.count(10)
>>>t3=t[6::] 3
>>>t3 >>>t1.count(20)
(“They”, 8, 9, ‘We’) 2
>>>t1.count(50)
Packing and Unpacking Tuples 1
>>>t1.count(90)
In Python, tuples are collections of elements which are 0
separated by commas. It packs elements or value together so,
this is called packing. In other way, it is called unpacking of a (iii) any( )
tuple of values into a variable.
This function returns True if atleast one element is present in
In packing, we put values together into a new tuple while in the tuple, otherwise returns False.
unpacking we extract those values into a single variables.
Syntax any(tuple_name)
Syntax variable1, variable2, ......, variableN = tuple_name
For example,
For example, >>>t1=(3, 6, 4)
>>>tuple1=(34, “Hello”, 54, 89, “world”) >>>any(t1)
To unpack the tuple, take variables equivalent to number of True
elements in that tuple and write this >>>t2=(2,)
>>>a, b, c, d, e = tuple1 >>>any (t2)
Now, print individual variable which display the element of True
tuple. >>>t3=()
>>>print(a)
>>>any (t3)
34
>>>print(b) False
Hello
>>>print(c)
(iv) max()
54 This function is used to return the element with maximum
>>>print(d) value out of elements present in tuple.
89 Syntax max (tuple_name)
>>>print(e)
For example,
world
>>>t1=(34, 65, 77, 45, 87, 99, 90)
Built-in Functions >>>max (t1)
99
In Python, tuple has large number of built-in functions which >>>t=(34, 65, “The”)
perform various operations and make the task easier. Some of >>>max(t)
them are describe below Trackback (most recent call last):
(i) len() File “<pyshell#5>”, line 1, in <module>
max(t)
This function is used to count the number of elements that
TypeError : unorderable types : str( )>int( )
present in the tuple.
>>>t=(‘a’, ‘f’, ‘F’, ‘u’)
Syntax len(tuple_name) >>>max(t)
For example, ‘u’
>>>t1=(45, “The”, 67, 54, “That”, 90) It will return max value of character using ASCII value.
>>>len(t1)
6 (v) min()
>>>t2=(45, “The”, (67, 64), “That”, 90) This function is used to return with minimum value out of
>>>len(t2) elements present in tuple.
5 Syntax min(tuple_name)
CBSE Term II Computer Science XI 21

For example, (ix) sum()


>>>t1=(34, 65, 77, 45, 87, 99, 90)
This method is used to calculate the sum of elements of
>>>min(t1)
tuple. The elements of tuple must be integer.
34
>>>t=(‘a’, ‘f’,‘F’, ‘u’) Syntax sum(tuple_name)
>>>min(t) For example,
‘F’ >>>marks=(78, 98, 80, 65, 75, 80)
>>>t2=(“Ansh”, “Yash”, “Sahil”) >>>print (“Total marks :”, sum(marks))
>>>min(t2)
Total marks : 476
‘Ansh’

(vi) sorted() (x) reversed()


This method allows us to process the items in a sequence in
This function is used to sort the given tuple in ascending
reverse order. It accepts a sequence and returns an iterator.
order. But this method returns the elements in square
brackets. Syntax iterator = reversed (sequence)
Syntax sorted(tuple_name) Here, sequence is a tuple.
For example, For example,
>>>t=(32, 45, 25, 33, 55, 89, 47, 78) >>>marks=(78, 98, 80, 65, 75, 80)
>>>sorted(t) >>>t=reversed(marks)
[25, 32, 33, 45, 47, 55, 78, 89] >>>t
>>>t1=(‘a’, ‘r’, ‘T’, ‘R’, ‘e’, ‘E’) <reversed object at 0X00F49F70>
>>>sorted(t1) >>>for i in t:
[‘E’, ‘R’, ‘T’, ‘a’, ‘e’ , ‘r’] print(i)
80
(vii) index()
75
It returns the index of first occurrence of element in the 65
tuple.
80
Syntax tuple_name.index(element) 98
For example, 78
>>>t=(45, 89, 9, “The”, 23, “That”, “This”, 25) or >>>tuple(reversed (marks))
>>>t.index(‘The’) (80, 75, 65, 80, 98, 78)
3
>>>t.index(9)
2 Deleting a Tuple
>>>t.index(25) Tuples are immutable and cannot be deleted individual
7 element from it but deleting tuple entirely is possible by
>>>t.index(“Those”) using the keyword “del”.
Trackback (most recent call last): For example,
File “<pyshell#8>”, line 1, in <module> t1=(4, 6, 3, 7, 6, 5, 0)
t.index(“Those”) print(“Tuple is :”, t1)
ValueError : tuple.index(x) : x not in tuple. del(t1)
(viii) tuple() print(“Tuple after deletion”)
print(t1)
This function is used to convert string and list into tuple.
Output
Syntax tuple(list/string)
Tuple is : (4, 6, 3, 7, 6, 5, 0)
For example, Tuple after deletion
>>>name=“NIHARIKA”
Trackback (most recent call last) :
>>>tuple(name)
(‘N’, ‘I’, ‘H’, ‘A’, ‘R’, ‘I’, ‘K’, ‘A’)
File “<pyshell#6>”, line 1, in <module>
>>>num = [4, 6, 3, 7, 2, 4, 0, 7]
print(t1)
>>>tuple (num) NameError: name ‘t1’ is not defined
(4, 6, 3, 7, 2, 4, 0, 7)
22 CBSE Term II Computer Science XI

Chapter
Practice
PART 1 4. Is the following Python code valid?
>>>tup1=(56, 25,36, 15)
Objective Questions >>> result=tup1.update(4,)
(a) Yes, tup1=(56, 25, 36, 15,4) and result=(56, 25, 36, 15,4)
(b) Yes, tup1=(56, 25, 36,15) and result=(56, 25, 36, 15,4)
l
Multiple Choice Questions (c) No, because tuples are immutable
(d) No, because wrong syntax for update() method
1. Which of the following is a collection of Python
Ans. (c) Tuple does not have any update() attribute because it is
objects separated by commas and represent as (,)?
immutable and cannot be changed after creation.
(a) List (b) Tuple
(c) Dictionary (d) String 5. What is the output of following code?
Ans. (b) A tuple is a collection of Python objects separated by t=(4,0, ‘Hello’, 90, ‘Two’, (‘One’, 45), 34, 2)
commas and represent as (,). Tuples are immutable by t1=t[1]+t[−2]
design which means they cannot be changed after creation. print(t1)
It holds a sequence of heterogeneous elements. (a) 34 (b) 38
e.g. T = (3, 4, 7, 6) (c) Hello34 (d) 45
Ans. (a) Value of t[1] is 0 because index number is 1 and value of
2. What will be the output of the following Python t[ −2 ] is 34 because index number is started from −1 at the
code? end point. t1 will store the sum of both values, i.e.
>>> a=(1,2,(4,5)) 0+34=34.
>>> b=(1,2,(3,4))
>>> a<b
6. What is the output of following code?
(a) False t=(1, 2, ‘Hello’, ‘The’, 3, 4)
(b) True print(max(t))
(a) ‘Hello’ (b) 4
(c) Error, < operator is not valid for tuples.
(c) ‘The’ (d) Error
(d) Error, < operator is valid for tuples but not if there are
Ans. (d) This code will give an error because ‘>’ (max) not
sub-tuples.
Ans. (a) Since the first element in the sub-tuple of ‘a’ is larger supported between instances of ‘str’ and ‘int’.
that the first element in the sub-tuple of ‘b’, hence False is 7. To create a tuple in Python, put all the elements in
printed. a
3. What is the output of the following code? (a) () (b) []
t1=(70, 56, ‘Hello’, 22, 2, ‘Hi’, ‘The’, ‘World’, 3) (c) {} (d) <>
print(t1 [2:4]) Ans. (a) To create a tuple in Python, put all the elements in a
(a) (56, ‘Hello’) parentheses (), separated by commas. We can have tuple of
(b) (‘Hello’, 22) same type of data items as well as mixed type of data items.
>>> t = ()
(c) (‘Hello’, 22,2)
>>> print(t)
(d) (56, ‘Hello’, 22) ()
Ans. (b) (:) is a slice operator, which returns the sub-part of any
data type as string, list, tuple etc. Index number is started
8. Suppose t1 = (3, 4, 5,8, 2, 1)
from 0, so the value of index number 2 is ‘Hello’ and this Find the value of t1[3.5].
will display the elements till last index number − 1, i.e. (4 − (a) 8 (b) 2
1=)3. (c) 5 (d) Error
So, the correct output is (‘Hello’, 22). And. (d) It will give TypeError because tuple’s index must be
integers or slices, not float.
CBSE Term II Computer Science XI 23

9. Suppose tuple t1 = (3, 4, 5, 6, 7, 8) Ans. (b) t1[4] = 7 means updation which is not possible in tuple
because tuple is immutable which cannot be changed after
Choose the correct option for t1[6].
creation.
(a) 1 (b) 8
(c) None (d) Error 15. What is the output of following code?
Ans. (d) It will give IndexError because tuple index is out of T = (100)
range. Its maximum index is 5 because index is started from print (T * 2)
0 but in t1[6] asked about index number 6, so it will give an (a) Syntax error (b) (200,)
error. (c) 200 (d) (100, 100)
10. Tuple packs elements or value together, so this is Ans. (c) Tuple T contains a single element, so * is used as
multiplication operator.
called
So, T * 2 = 100 * 2 = 200
(a) pickling (b) unpacking
(c) packing (d) unpickling 16. What will be the output of the following Python
Ans. (c) Tuple packs elements or value together, so this is called code?
packing. In packing, we put values together into a new tuple >>> a=(5,6)
while in unpacking we extract those values into a single >>> b=(2,6)
variable. >>> c=a+b
>>> c
11. Choose the correct output. (a) (7,12)
a = (2, 4, 3, 4) (b) (5,6,2,6)
b = (5, 8, 9)
(c) Error as tuples are immutable
t =a + b
(d) None
print(t)
Ans. (b) In the above piece of code, the values of the tuples are
(a) (2, 4, 3, 4, 5, 8, 9) (b) (7, 12, 12, 4)
not being changed. Both the tuples are simply concatenated.
(c) (2, 10, 13, 4, 9) (d) Error
Ans. (a) To concatenate tuples, (+) operator is used in Python. 17. Choose the correct option.
This operator can easily add the whole of one tuple to other (a) In Python, a tuple can contain only integers as its
tuple and perform concatenation. This operator cannot add elements.
one tuple with other type as number or string, otherwise it (b) In Python, a tuple can contain only strings as its
will give error in such conditions. elements.
(c) In Python, a tuple can contain both integers and strings
12. Suppose tuple t1 = (4, 7, 3, 6, 8, 9) as its elements.
Choose the correct option for t1[: 4]. (d) In Python, a tuple can contain either string or integer but
(a) (3, 6, 8, 9) (b) (4, 7, 3, 6) not both at a time.
(c) (6) (d) (8, 9) Ans. (c) In Python, a tuple can contain both integers and strings
as its elements is the correct option.
Ans. (b) To display a specific range of elements from the tuple, we
use slicing operation. This operation in performed on tuples
with the use of colon (:).
l
Case Based MCQs
To display elements from beginning to a range, use [: index]. 18. Suppose that tuple
So, t1[: 4] will print the element from starting to index−1.
t1=(“Hello”, (“am”, “an”), (“that”, “the”, “this”), “you”,
13. Given a tuple t1= (1, 2, 3, 4, 5, 6, 7, 8, 9). What will “we”, “those”, “these”)
be the output of print (t1 [3 : 7 : 2])? Based on the above information, answer the
(a) (4, 5, 6, 7, 8) (b) (4, 5, 6, 7) following questions.
(c) (4, 5, 6) (d) (4, 6)
(i) Choose the correct option for len(t1).
Ans. (d) t1[3 : 7 : 2] starts from index number 3 to index number (a) 7 (b) 10
7 with gap of 2 elements.
(c) None (d) Error
In t1= (1, 2, 3, 4, 5, 6, 7, 8, 9), element of index number 3 is 4
and after two elements of gap, element is 6. So, output is (ii) What is the output of following code?
(4, 6). print(t1[3 :5])
(a) (‘the’, ‘this’) (b) (‘am’, ‘an’)
14. Given a tuple t1= (1, 2, 3, 4, 5). Identify the (c) (‘you’, ‘we’) (d) (‘you’, ‘we’, ‘those’)
statement that will display an error.
(a) print (t1[3])
(iii) Identify the output of t1[5 : ] + t1[2].
(a) (‘those’, ‘these’, ‘that’)
(b) t1[4] = 7
(b) (‘those’, ‘these’, ‘that’, ‘the’, ‘this’)
(c) print (len (t1))
(c) (‘the’, ‘this’)
(d) print (max (t1)) (d) Error
24 CBSE Term II Computer Science XI

(iv) Identify the output of print (t1[6:]). 2. Explain the mixed data types tuple with an
(a) (‘these’,) example.
(b) (‘those’) Ans. Mixed data types can be created to place different
(c) ‘these’ data types such as integers, strings, double etc into one
(d) Error tuple. For example,
(v) Find the correct output of print (t1[−3]*2). tuple1=(‘English’, 90, ‘Rahul’,‘Meerut’, ‘99.5’)
(a) wewe 3. Observe the following tuple and answer the
(b) youyou questions that follow.
(c) None
t1=(76, 56, ‘Harish’, ‘Ansh’, 98, (45, 34), ‘Muskan’)
(d) IndexError
Ans. (i) (a) len() is used to count the number of elements that
(i) len(t1) (ii) t1[−6]
present in the tuple. Given tuple is a nested tuple, so (iii) t1[3] (iv) t1[: 2]
(“am”, “an”) will considered as one element and (“that”, Ans. (i) 7
“the”, “this”) will considered as one element. Then, this
(ii) 56
will give 7 as output.
(ii) (c) To display a specific range of elements from the tuple, (iii) 'Ansh'
we use slicing operation. This operation is performed on (iv) (76, 56)
tuples with the use of colon (:).
t1[3 : 5] displays the element from index number 3, i.e.
4. Explain sum() method of tuple with an example.
‘you’ to index number ( 5 − 1 = ) 4 i.e. we. So, output will Ans. sum() method is used to calculate the sum of elements of
be (‘you’, ‘we’). tuple. The elements of tuple must be integer.
(iii) (b) To display elements from specific index till the end, Syntax sum(tuple_name)
use [index :], so t1[5:] will display the elements from For example,
index number 5 to till end i.e. (‘those’, ‘these’). >>>price=(100, 150, 95, 120, 80)
To access a particular element, use [index], so t1[2] will >>>sum(price)
display the element of index number 2, i.e. (‘that’, ‘the’, Output
‘this’).
+ operator is used to concatenate the tuples. 545
(iv) (a) To display elements from specific index till the end, 5. Observe the following tuples and answer the
use [Index :]. questions that follow.
So, t1[6:] will display the element from index number 6, t1=(4, 7, 8, 9)
i.e. ‘these’ till the end. t2=(0, 4, 3)
(v) (a) Index number − 3 represents the third element from
end i.e. ‘we’. * is the replication operator that can repeat (i) >>>t=t1+t2
the elements of the tuple. >>>print(t)
So, ‘we’ will be repeat two times because * 2 is given. (ii) >>>t=t1*t2
>>>print(t)
Ans. (i) (4, 7, 8, 9, 0, 4, 3)
PART 2 (ii) It gives TypeError because cannot multiply sequence by
non-int of type ‘tuple’.
Subjective Questions 6. Write a Python program to find maximum and
minimum elements in a tuple.
l
Short Answer Type Questions Ans. tuple1 = (23,45,−65,−45,20,45,65,− 24)
print(“The tuple is:”,tuple1)
1. Distinguish between tuple and list. min1 = tuple1.index (min(tuple1))
Ans. Differences between tuple and list are as follows max1 = tuple1.index (max(tuple1))
Tuple List print(“Maximum element in the tuple is :”, max(tuple1),“ at
index number ”,max1)
Elements of a tuple are Elements of a list are
immutable. mutable. print(“Minimum element in the tuple is :”, min(tuple1),“ at
index number ”,min1)
Tuple is declared in List is declared in square
parenthesis (). brackets [ ]. 7. What do you mean by membership operators in
Tuples cannot be changed Lists can be changed after
Python?
after creation. creation. Ans. Membership operators are used to check whether a
value/variable exists in the sequence like string, list, tuple
Iterating over the elements Iterating over the elements of etc. These operators return True or False as per conditions
of a tuple is fast. a list is slow. met.
CBSE Term II Computer Science XI 25

Membership operators are of two types as: else :


(i) in operator print (“x is present in given tuple”)
(ii) not in operator if(y in tuple):
print(“y is present in given tuple”)
8. Explain tuple slicing syntax with its parameters.
else:
Ans. Syntax t=tuple_name[start : stop : step]
print(“y is NOT present in given tuple”)
Here,
Ans. x is NOT present in given tuple
lstart integer where the slicing of the object starts.
y is present in given tuple
lstop integer until which the slicing takes place. The slicing
stops at index stop −1. 13. What is the output of following code?
lstep integer value which determines the increment t1=(1, 2, 3, 4, 5)
between each index for slicing. print(“Tuple is :”, t1)
del(t1)
9. Find the output of the given questions print(“Tuple after deleting”)
t=(45, 76, 23, ‘The’, 89, (‘This’, 56), (23, ‘That’),34) print(t1)
(i) (t[4]) Ans. Output
(ii) t[2:10:3] Tuple is : (1, 2, 3, 4, 5)
Tuple after deleting
(iii) t[2] + t [–1] Trackback (most recent call last) :
Ans. (i) 89 File “<pyshell#6>”, line 1, in <module>
(ii) (23,('This', 56)) print(t1)
(iii) 57 NameError: name ‘t1’ is not defined
10. Find the output of following code? 14. Find and write the output of the following Python
t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’) code.
for i in range (len(t)): t=(4, (8, 0, 7))
print (t[i]) t1=(4, 7, (2, 8))
Ans. Output print(t.count(0))
A print(t[1][2])
print(t*2)
R
print(len(t1))
I print(t1[2])
H print(t+t1)
A Ans. Output
N 0
T 7
11. What will be the output of following code? (4, (8, 0, 7), 4, (8, 0, 7))
tuple1=(1,2,3,4,5) 3
tuple2=(6,7,8,9) (2, 8)
(4, (8, 0, 7), 4, 7, (2, 8))
for item in tuple1:
if item in tuple2: 15. Identify the error, if any in the following code.
print(“overlapping”) t1=(2, 3, 4, ‘Hello’, 6,9)
else: print (min(t1))
print(“not overlapping”) Ans. min() function is used in tuple to return with minimum
Ans. Output value out of elements in tuple.
not overlapping Given code has an error because min() will work only if
elements in a tuple are of same data type, i.e. (2, 3, 4, 7, 6, 9).
12. What will be the output of following code?
x=44 16. Write a Python code to remove an element ‘2’ from
y=30 the following tuple.
tuple = (45, 65, 30, 78, 512) tuple1 = (2, 5, 6, 9, 4)
if(x not in tuple): Ans. tuple1 = (2, 5, 6, 9, 4)
print(“x is NOT present in given tuple”) list1 = list (tuple1)
list1. remove (2)
tuple1 = tuple (list1)
print (tuple1)
26 CBSE Term II Computer Science XI

17. Write a Python code to display all the elements of (iii) Equal to (= =) operator
the following tuple except ‘H’. (iv) Packing
t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’) Ans. (i) Tuple is a collection of Python objects separated by
Ans. t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’) commas (,) and put the elements in parentheses ( ).
t = t[0 : 3] + t[−3 : ] (ii) in operator is used to check, if a value exists in a sequence.
print (t) (iii) Equal to (= =) operator returns True if the values on
either side of the operator are equal.
Output
(iv) Tuples put all the elements or values together in a
(‘A’, ‘R’, ‘I’, ‘A’, ‘N’, ‘T’) parentheses, is called packing.
18. TypeError occurs while statement 2 is running. 21. Answer the following questions;
Give reason. How can it be corrected?
(i) t1=(25, 78, (45, (65, 89)), 90, (34, 8))
>>> tuple1 = (5) #statement 1 len (t1)
>>> len(tuple1) #statement 2 [NCERT] (ii) t2=(45,(‘The’,78,(‘This’),67),‘The’,67, 67)
Ans. The ‘statement 1’ is creating a variable, tuple1 which is of t2.count(67)
‘int’ data type. The ‘statement 2’ is checking for the length of
the variable, but the argument passed is an ‘int’ data type. (iii) t1=(3,)
The len() function can return the length only when the t2=()
object is a sequence or a collection. This is the reason for t=t1+t2
the type error. any(t)
The error can be corrected by adding one comma after ‘5’ in (iv) t3=(87, 89, 56, 99, 75, 45, 100)
statement 1, as this will create a tuple and as a tuple is a
max(t3)
collection, len() function will not return an error.
Ans. (i) 5 (ii) 2 (iii) True (iv) 100
The correct statement will be
>>> tuple1 = (5,) 22. Write a Python program to count the number of
>>> len(tuple1) elements in a given range using traversal. Also,
19. Prove with the help of an example that the variable display its output.
is rebuilt in case of immutable data types. [NCERT] Ans. c=0
l=40
Ans. When a variable is assigned to the immutable data type, the
r=80
value of the variable cannot be changed in place.
tuple1=(10, 20, 30, 40, 50, 40, 40, 60, 70)
Therefore, if we assign any other value of the variable, the for x in tuple1:
interpreter creates a new memory location for that value and
if x>=l and x<=r:
then points the variable to the new memory location. This is
c+=1
the same process in which we create a new variable. Thus, it
can be said that the variable is rebuilt in case of immutable print(“Tuple:”, tuple1)
data types on every assignment. print(“Elements in a tuple:”,c)
Program to represent the same: Output
v = 20 Tuple : (10, 20, 30, 40, 50, 40, 40, 60, 70)
print(“Before: ”,id(v)) Elements in a tuple : 6
v = 21
print(“After: ”,id(v))
23. Write a Python program to find the common
elements in two tuples.
Output
Ans. tuple1=(45,87,56,−78,36,−12)
Before: 140705582623120
tuple2=(65,32,45,−78,36,−75)
After: 140705582623152
a_set = set(tuple1)
It can be seen that the memory location a variable is pointing
after the assignment is different. The variable is entirely new b_set = set(tuple2)
and it can be said that the variable is rebuilt. if (a_set & b_set):
print(“Common elements are:”,a_set &
l
Long Answer Type Questions b_set)
else:
20. Write the short note on following terms. print(“No common elements”)
(i) Tuple Output
(ii) in operator Common elements are: {−78, 36, 45}
CBSE Term II Computer Science XI 27

24. Write a Python program to calculate the sum and Find the output of the following statements.
mean of the elements in a tuple. (i) print(tuple1.index(45))
Ans. tuple1 = (23,45,20,45,65,24) (ii) print(tuple1.count(45))
print(“The tuple is:”,tuple1)
(iii) print(tuple1 + tuple2)
sm=0
for i in range(len(tuple1)): (iv) print(len(tuple2))
sm=sm+tuple1[i] (v) print(max(tuple1))
mean=sm/num (vi) print(min(tuple1))
print(“SUM = ”,sm)
(vii) print(sum(tuple2))
print(“MEAN = ”,mean)
Output (viii) print(sorted(tuple1))
The tuple is: (23, 45, 20, 45, 65, 24) print(tuple1) [NCERT]
SUM = 222 Ans. (i) 2
MEAN = 44.4 (ii) 3
25. Write a program to find the occurrence of a given (iii) (23, 1,45, 67,45, 9, 55, 45, 100, 200)
element. (iv) 2
Ans. t = (23,45,20,−45,65,24,−45,−23) (v) 67
print(“The tuple is:”,t) (vi) 1
k=0 (vii) 300
num=int(input(“Enter the number to be (viii) [1, 9, 23, 45, 45, 45, 55, 67]
counted:”))
(23,1,45,67,45,9,55,45)
for j in t:
if(j==num): 28. Write a program to read email IDs of n number of
k=k+1 students and store them in a tuple. Create two new
print(“Number”,num,“is appear”,k, “times.”) tuples, one to store only the usernames from the
Output email IDs and second to store domain names from
The tuple is: (23, 45, 20, − 45, 65, 24, − 45, − 23) the email IDs. Print all three tuples at the end of
Enter the number to be counted:45 the program.
Number 45 is appear 1 times. [Hint You may use the function split()] [NCERT]
26. Write a Python program to search an element with Ans. num = int(input(“Enter number of students: ”))
its index number. list1=[]
Ans. tuple1=(12,65,78,−63,−2,3,78,−12) for i in range(num):
sm=0
email=input(“Enter email: ”)
x = int(input(“Enter number to be searched:”))
found = False list1.append(email)
for i in range(len(tuple1)): tuple1=tuple(list1)
if(tuple1[i] == x): username=[]
found = True
print(“%d found at %drd domain=[]
position”%(x,i)) for i in tuple1:
break n,d = i.split(“@”)
if(found == False):
username.append(n)
print(“%d is not in tuple”%x)
Output domain.append(d)
Enter number to be searched: − 63 username = tuple(username)
− 63 found at 3rd position domain = tuple(domain)
print(“Names = ”,username)
27. Consider the following tuples, tuple1 and tuple2.
print(“Domains = ”,domain)
tuple1 = (23,1,45,67,45,9,55,45)
print(“Tuple = ”,tuple1)
tuple2 = (100,200)
28 CBSE Term II Computer Science XI

29. A tuple is a collection of objects which ordered and (iii) Write the syntax to create tuple from an existing
immutable. Tuples are sequences, just like lists. sequence.
The differences between tuples and lists are, the (iv) Observe the output of giving code.
tuples cannot be changed unlike lists and tuples >>>t=[“T”, “U”, “P”, “L”, “E”]
use parentheses, whereas lists use square brackets. >>>t2 = tuple(t)
We can use the index operator [] to access an item >>>t2
in a tuple, where the index starts from 0. (v) What is traversing a tuple in Python?
So, a tuple having 6 elements will have indices Ans. (i) Tuples hold a sequence of heterogeneous elements.
from 0 to 5. Trying to access an index outside of the (ii) Nested tuples are tuple objects where the elements in
tuple index range(6,7,... in this example) will raise the tuples can be tuples themselves.
an IndexError. (iii) new_tuple_name=tuple(sequence)
(iv) (‘T’, ‘U’, ‘P’, ‘L’, ‘E’)
(i) Which types of elements are stored in tuple? (v) Traversing a tuple is a technique to access an individual
(ii) What do you mean by nested tuples? element of that tuple.
Chapter Test
Multiple Choice Questons 9. Suppose the tuple t1 = (2, 3, 4, 7, 1, 6). Find
1. Consider the declaration obj = (2 , ‘Hello’, 3, 4). What (i) t1.index(4)
will be the data type of obj? (ii) t1.count(4)
(a) List (b) Tuple 10. Suppose the tuple t1 = (2, 3, 2, 2, 3, 4, 6, 7).
(c) Dictionary (d) String (i) count (t1) (ii) len(t1)
2. What is the output of followig code? 11. Observe the given tuples and answers the questions
t1=(1, 2, 3, 4, 5, 6, 7, 8) t1 = (1, 2, 3, 4 )
print (t1[2 : 4]) t2 = (5, 6, 7)
(a) (3, 4) (b) (2, 3) (i) >>> t = t1 + t2
(c) (4, 5, 6) (d) (3, 4, 5) >>> print(t)
3. Choose the correct option with respect to Python. (ii) >>> t = t1* t2
(a) Both tuples and lists are immutable. >>> print(t)
(b) Tuples are immutable while lists are mutable.
(c) Both tuples and lists are mutable.
12. Consider the tuple t = (2 ,3 , ‘Hello’, 2, 5, 9) and find out
(d) Tuples are mutable while lists are immutable. the error if any in following code
tuple1 = t + 5
4. Which of the following options will not result in an print(tuple1)
error when performed on tuples in Python where
tupl=(5,2,7,0,3)?
13. Compare the tuple and write the output.
(i) t1 = (4, 5, 6, 9)
(a) tupl[1]=2
t2 = (6, 9, 5, 6)
(b) tupl.append(2)
print(t1 < t2)
(c) tupl1=tupl+ tupl (ii) t1 = (4, 5, 6, 9)
(d) tupl.sort() t2 = (4.0, 5.0, 6.0, 9.0)
5. What will be the output of the following Python code? print(t1 = = t2)
>>>my_tuple = (10, 20, 30, 40)
Long Answer Type Questions
>>>my_tuple.append((50, 60))
>>>print (len(my_tuple)) 14. Write a Python program to count the positive numbers
(a) 1 (b) 6 and negative numbers in a tuple.
(c) 4 (d) Error 15. Write the most appropriate tuple methods for the
6. Is the following Python code valid? following conditions.
>>> a,b=1,2,3 (i) To count the number of elements in a tuple.
(a) Yes, this is an example of tuple unpacking, where a=1 and (ii) Calculate total occurence of given element.
b=2. (iii) Returns the element with maximum value.
(b) Yes, this is an example of tuple unpacking, where a=(1,2) (iv) Returns the element with minimum value.
and b=3.
(v) To sort the given tuple in ascending order.
(c) No, too many values to unpack.
(vi) Returns true if atleast one element is present in the
(d) Yes, this is an example of tuple unpacking, where a=1 and
tuple.
b=(2,3).
(vii) Returns the index of first occurrence of element.
Short Answer Type Questions (viii) Converts string and list into tuple.
7. Observe the following tuple and answer the questions 16. Write a Python program to test if a variable is a list or
that follow tuple.
t = (1, 2, 3, 4, 5,6 ,7,8, 9,10)
17. Write a Python program to sort a list of tuples by the
(i) t[−3] second Item.
(ii) t[: 2]
18. Write a Python program to sort a list of tuples
8. Explain the any () method of tuple with an example. alphabetically.

Answers For Detailed Solutions


Multiple Choice Questions Scan the code
1. (b) 2. (a) 3. (b) 4. (c) 5. (d) 6. (c)
30 CBSE Term II Computer Science XI

CHAPTER 03

Dictionary
In this Chapter...
l Creating a Dictionary l Adding Elements to Dictionary

l Properties of Dictionary Keys l Updating Elements in a Dictionary

l Traversing a Dictionary l Deleting Element from a Dictionary

l Accessing Keys l Membership Operators


or Values Separately l Built-in Methods

In Python, dictionary is an unordered collection of data Key : Value Pair Key Value
values that stored the key : value pair instead of single value “Abhi” : “Manager” “Abhi” “Manager”
as an element. Keys of a dictionary must be unique and of “Manish” : “Project Manager” “Manish” “Project Manager”
immutable data types such as strings, tuples etc. Immutable
means they cannot be changed after creation. But in “Aasha” : “Analyst” “Aasha” “Analyst”
dictionary, key-value can be repeated and be of any type. “Deepak” : “Programmer” “Deepak” “Programmer”
A dictionary is used to map or associate things you want to “Ishika” : “Tester” “Ishika” “Tester”
store the keys you need to get them. A dictionary in Python is We can also create empty dictionary.
just like a dictionary in the real world. Each key-value pair in
a dictionary is separated by a colon (:) whereas each key is For example, dic1 = { }
separated by a comma (,). In dictionary, key will be a single Dictionaries are also called mappings or hashes or associative
element and values can be a list or list within a list, numbers arrays.
etc. If you give list as key, then it will give an Error
>>> dic = {[1, 2]: “math”}
Creating a Dictionary Trackback (most recent call last):
To create a dictionary in Python key : value pair is used. File “<pyshell#7>”, line 1, in <module>
Dictionary is listed in curly brackets, inside these curly dic = {[1, 2]: “math”}
brackets, keys and values are declared. TypeError : unhashable type : ‘list’
Syntax dictionary_name = {key1 : value1, key2 : value2, …}
For example, Properties of Dictionary Keys
>>>Employees = {“Abhi” : “Manager”, “Manish” : “Project There are following points while using dictionary keys as
Manager”, “Aasha” : “Analyst”, “Deepak” : “Programmer”, follows
“Ishika” : “Tester”} (i) More than one entry per key is not allowed (no
>>> Employees duplicate key is allowed).
Here is the example of dictionary named Employees in (ii) Dictionaries’ keys are case sensitive, same key name
which Emplyees’ names stored as keys and designation but with the different case are treated as different in
stored as values of respected keys. Python.
Output (iii) The values in the dictionary can be of any type while
{‘Abhi’: ‘Manager’, ‘Manish’ : ‘Project Manager’, the keys must be immutable like numbers, tuples or
‘Aasha’ : ‘Analyst’, ‘Deepak’ : ‘Programmer’, ‘Ishika’ : ‘Tester’} strings.
We can separate these dictionaries as follows
CBSE Term II Computer Science XI 31

Accessing Elements from a Output


Keys are
Dictionary 1
In Python, to access the elements from a dictionary, keys are 2
used. While in tuple and list, index is used to access the 3
elements. 4
Syntax dictionary_name[key]
(ii) Iterate Through All Values
To access the respective value of key, that key has to given in
square bracket with dictionary name. Again, in above example, the order of subjects are printed
will change every time.
For example,
For example,
>>>Employees [“Deepak”]
>>>print (“Values are”)
‘Programmer’ >>>for i in dic:
>>>Employees [“Ishika”] print(dic [i])
‘Tester’ Output
You can also give this as Values are
Math
>>>print (“Manish works as a”, Employees [‘Manish’])
Manish works as a Project Manager Science
If you give a key that does not exist in dictionary, then it will English
give an error. So, before to access the value first ensure that Music
key is available in dictionary or not.
(iii) Iterate Through All Keys Value Pairs
>>>Employees [“Tushar”]
We can also iterate dictionary through all keys value pairs.
Trackback (most recent call last):
File “<pyshell#11>”, line1, in <module> For example,
>>>print (“Keys :Values”)
Employees [“Tushar”]
>>>for i in dic :
KeyError : ‘Tushar’
print(i, “:”, dic [i])
If you do not give any key with dictionary name, then it will
give whole dictionary with different order. Output
Keys : Values
For example,
1 : Math
>>>dic = {‘1’ : “Math”, ‘2’ : “Science”, ‘3’ : “English”}
2 : Science
>>>dic
3 : English
{‘1’ : ‘Math’, ‘3’ : ‘English’, ‘2’ : ‘Science’}
4 : Music

Traversing a Dictionary Accessing Keys or


Traversing a dictionary means access each and every element
of it. We can traverse a dictionary using for loop. Values Separately
For example, You can access the keys or values separately in dictionary. To
dic = {1 : “Math”, 2 : “Science”, 3 : “English” 4 : “Music”} access the keys from dictionary, use
There are multiple ways to iterate over (traversing) a (dictionary_name). keys () and to access the values of
dictionary in Python as follows respected keys, use (dictionary_name). values ()
For example,
(i) Iterate Through All Keys >>>dic1 = {“A” : “Science”, “B” : “Math”, “C” : “Computer”,
In above example, the order of subject number will change “D” : “English”}
every time because the dictionary does not store keys in a >>>dic1.keys ()
particular order. dict_keys ([‘B’, ‘C’, ‘A’, ‘D’])
>>>print (“Keys are”) >>>dic1.values ()
>>>for i in dic : dict_values ([‘Math’, ‘Computer’, ‘Science’, ‘English’])
print(i) You can also convert these returned keys and values in list
form.
32 CBSE Term II Computer Science XI

For example, Updating Elements


>>>list (dic1.keys())
[‘B’, ‘C’, ‘A’, ‘D’]
in a Dictionary
>>list (dic1.values ()) You can update elements that are already exist in a
[‘Math’, ‘Computer’, ‘Science’, ‘English’]
dictionary.
Syntax
Nested Dictionary dictionary_name [key] = value
For example,
Nested dictionary means putting a dictionary inside another
dictionary. Nesting is of great use as kind of information we >>>Student = {11 : ‘Ashi’, 12 : ‘Shivam’, 13 : ‘Shrey’, 14 :
can model in programs expanded greatly. ‘Vicky’}
Syntax >>>Student [12] = ‘Nishant’
Nested_dict = {‘dictA’ : {‘key1’ : ‘value1’}, ‘dictB’ : {‘key2’ : >>>Student
‘value2’}} {11 : ‘Ashi’, 12 : ‘Nishant’, 13 : ‘Shrey’, 14 : ‘Vicky’}
Here, the Nested_dict is a nested dictionary with the You entered a key which is not available in a dictionary, then
dictionary dictA and dictB. They are two dictionaries and it will add that key with respective value.
each having own key and value. >>>Student [15] = ‘Kansal’
For example, >>>Student
>>>Student = {112 : {‘Name’ : ‘Surbhi’, ‘Marks’ : 450, ‘Age’ {11 : ‘Ashi’, 12 : ‘Nishant’, 13 : ‘Shrey’, 14 : ‘Vicky’, 15 :
: 16}, 115 : {‘Name’ : ‘Sahil’, ‘Marks’ : 470, ‘Age’ : 16}} ‘Kansal’}
>>>Student
{112 : {‘Marks’ : 450, ‘Age’ : 16, ‘Name’ : ‘Surbhi’}, Deleting Element from a
115 : {‘Marks’ : 470, ‘Age’ : 16, ‘Name’ : ‘Sahil’}}
Dictionary
Adding Elements to Dictionary There are following ways to delete elements from a
dictionary as follows
In Python dictionary, adding of elements extend it with
single pair of values. One value at a time can be added to a (i) Using del Keyword
dictionary by defining value along with the key. This keyword is used to delete the key that is present in the
Syntax dictionary.
dictionary_name [key] = value Syntax
For example, del dictionary_name [key]
>>>Teacher = {‘Neha’ : ‘Hindi’, ‘Akshay’ : ‘Math’, ‘Parul’ : For example,
‘English’} >>>Teacher = {“Name” : “Ashi”, “Subject”: “Math”, “Id” :
>>>Teacher [‘Nisha’] = ‘Computer’ 2546, “Salary”: 25000}
>>>Teacher >>>Teacher
{‘Akshay’ : ‘Math’, ‘Nisha’ : ‘Computer’ , ‘Neha’ : ‘Hindi’, {‘Subject’: ‘Math’, ‘Name’:
‘Parul’ : English’} ‘Ashi’, ‘Salary’ : 25000,
You can also adding elements into an empty dictionary by ‘Id’ : 2456}
dictionary_name [key] = value >>>del Teacher [‘Id’]
>>>dic = { } >>>Teacher
>>>dic {‘Subject’ : ‘Math’, ‘Name’ : ‘Ashi’, ‘Salary’ : 25000}
{} One drawback of this keyword is that if you want to delete
>>>dic [1] = “Delhi” key that is not exist in dictionary, then it will give exception
>>>dic [2] = “Meerut” error.
>>>dic [3] = “Agra” >>>del Teacher [‘Age’]
>>>dic [4] = “Chandigarh” Trackback (most recent call last):
>>>dic File “<pyshell#4>”, line 1, in <module>
{1 : ‘Delhi’, 2 : ‘Meerut’, 3 : ‘Agra’, 4 : del Teacher [‘Age’]
‘Chandigarh’} KeyError : ‘Age’
CBSE Term II Computer Science XI 33

(ii) Using pop () method Built-in Methods


This method is used to delete key and respective value from Python has some built-in methods that dictionary objects can
dictionary. call. Some of them are describe below
Syntax
dictionary_name.pop (key) (i) len()
For example, This method is used to return the total length of the
dictionary.
>>>Teacher = {‘Name’ : ‘Ashi’, ‘Subject’ : ‘Math’, ‘Id’ :
Syntax
2546, ‘Salary’ : 25000}
len(dictionary_name)
>>>Teacher
For example,
{‘Subject’ : ‘Math’, ‘Name’ : ‘Ashi’, ‘Salary’ : 25000, ‘Id’ :
>>>dic = {1 : ‘This’, 2 : ‘That’, 3 : ‘The’, 4 : ‘World’}
2546}
>>>len (dic)
>>>Teacher.pop (‘Id’) 4
2546 >>>del dic[2]
>>>Teacher >>>len (dic)
{‘Subject’ : ‘Math’, ‘Name’ : ‘Ashi’, ‘Salary’ : 25000} 3
Advantage over using del keyword is that it provides the >>>dic [5] = ‘Hello’
mechanism to print desired value if tried to remove a non >>>dic [6] = ‘Wonder’
existing dictionary pair. >>>len (dic)
>>>Teacher.pop (‘Age’, “Key not found in dictionary”) 5
‘Key not found in dictionary’ >>>dic
{1 : ‘This’, 3 : ‘The’, 4 : ‘World’, 5 : ‘Hello’, 6 : ‘Wonder’}
Membership Operators
in and not in membership operators are used with dictionary. (ii) clear()
These operators check whether a specific key is present in This method is used to remove the elements of the
dictionary or not. If it is present, then it will give True dictionary. It produces an empty dictionary. It will only
otherwise False. delete elements not a dictionary. It does not take any
Syntax parameter and does not return any value.
Key in dictionary_name Syntax
Key not in dictionary_name dictionary_name.clear()
For example, For example,
>>>Employee = {‘Id’:4598, ‘Name’: ‘Shubham’, >>>dic1 = {“Project” : “All In One”, “Days” : 15, “Level” :
‘Dept’:‘Programmer’, ‘Salary’:35000} “High”}
>>>dic1.clear()
>>>Employee
>>>dic1
{‘Id’:4598, ‘Name’:‘Shubham’, ‘Dept’:‘Programmer’,
{}
‘Salary’:35000}
If you want to delete the dictionary with its elements, then
>>>‘Age’ in Employee
del keyword is used.
False
>>>dic1 = {“Project” : “All in One”, “Days” : 15, “Level” :
>>>‘Id’ in Employee “High”}
True >>>del dic1
>>>‘Designation’ not in Employee >>>dic1
True Trackback (most recent call last) :
These operators do not work on values. File “<pyshell#5>”, line1, in <module>
>>>‘Shubham’ in Employee dic1
False NameError : name ‘dic1’ is not defined
If you want to used values with in and not in operators then
use dictionary_name.values() with value’s name. (iii) get()
>>>‘Shubham’ in Employee.values() This method returns the value for the given key, if present in
True the dictionary. It takes maximum of two parameters.
34 CBSE Term II Computer Science XI

Syntax (vi) values ( )


dictionary_name.get (Key[, value]) This method returns a view object that displays a list of all
Here, Key to be searched in the dictionary value (optional) the values in the dictionary. It does not take any parameters.
value to be returned if the key not found. The default value is Syntax
None.
dictionary_name.values ()
For example,
For example,
>>>Student = {‘Name’ : ‘Shyam’, ‘Roll No’ : 21, ‘Marks’ : 459,
>>>Teacher = {‘Name’ : ‘Akshat’, ‘Subject’ : ‘Science’,
‘Class’ : 12}
‘Salary’ : 28000, ‘Experience’ : 4}
>>>Student
>>>Teacher.values()
{‘Class’ : 12, ‘Roll No’ : 21, ‘Marks’ : 459, ‘Name’ : ‘Shyam’}
dict_values([28000, ‘Science’, ‘4’, ‘Akshat’])
>>>Student.get (‘Name’)
‘Shyam’ (vii) update ( )
>>>Student.get (‘Age’, ‘Not Found’)
This method updates the dictionary with the elements from
‘Not Found’ the another dictionary object or from an iterable of key/value
>>>Student.get (‘Marks’, ‘Not Found’) pairs.
459
Syntax
(iv) items () dictionary_name1.update (dictionary_name2)
This method returns a view object that displays a list of For example,
dictionary’s (key, value) tuple pairs. items() method does not >>>Teacher = {‘Name’ : ‘Akshat’, ‘Subject’ : ‘Science’,
take any parameters. ‘Salary’ : 28000}
Syntax >>>Teacher1 = {‘Name’ : ‘Akansha’, ‘Salary’ : 25000,
dictionary_name.items() ‘Experience’ : 5}
For example, >>>Teacher.update(Teacher1)
>>>Teacher = {‘Name’ : ‘Akshat’, ‘Subject’ : ‘Science’, >>>Teacher
‘Salary’ : 28000, ‘Experience’ : 4} (‘Salary’ : 25000, ‘Subject’, ‘Science’, ‘Experience’ : 5,
>>>Teacher. items () ‘Name’ : Akansha}
dict_items ([(‘Salary’, 28000), (‘Subject’, ‘Science’),
(‘Experience’, 4), (‘Name’, ‘Akshat’)]) (viii) sorted ()
We can also display this using for loop This method returns a sorted sequence of the keys in the
>>>dic = Teacher.items() dictionary.
>>>for i in dic : Syntax
print (i) sorted (dictionary_name)
Output For example,
(‘Salary’, 28000) >>>Teacher = {‘Name’ : ‘Akshat’, ‘Subject’ : ‘Science’,
(‘Subject’, ‘Science’) ‘Salary’ : 28000, ‘Experience’ : 4}
(‘Experience’, 4) >>>sorted(Teacher)
(‘Name’, ‘Akshat’) [‘Experience’, ‘Name’, ‘Salary’, ‘Subject’]
If a dictionary contains both string and integer as keys, then
(v) keys() it will give an error.
This method returns a view object that displays a list of all >>>dic = {‘One’ : ‘This’, 2 : ‘That’, ‘5’ : ‘World’, ‘Five’ :
the keys in the dictionary. It does not take any parameters. ‘Wonders’}
Syntax >>>sorted (dic)
dictionary_name.keys() Trackback (most recent call last):
For example, File “<pyshell#18>”, line 1, in <module>
>>>Teacher = {‘Name’ : ‘Akshat’, ‘Subject’ : ‘Science’, sorted(dic)
‘Salary’ : 28000, ‘Experience’ : 4} TypeError : unorderable types : str () < int ( )
>>>Teacher.keys()
dict_keys([‘Salary’, ‘Subject’, ‘Experience’, ‘Name’]) (ix) fromkeys()
This method creates a new dictionary from the given
sequence of elements with a value provided by the user.
CBSE Term II Computer Science XI 35

Syntax Syntax
dict.fromkeys(seq, value) dict.setdefault (key[, default_value])
For example, For example,
>>>key = {1, 2, 3, 4, 5} >>>dic = {‘Akshat’ : 26, ‘Riya’: 24, ‘Shrey’:27}
>>>value = dict.fromkeys (key) >>>dic1 = dic.setdefault (‘Riya’)
>>>print (value) >>>print (‘Dictionary : ’, dic)
{1: None, 2 : None, 3 : None, 4 : None, 5 : None} Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
>>>value1 = dict.fromkeys (key, ‘Hello’) >>>print (‘Founded key : ’, dic1)
>>>print (value1) Founded key : 24
{1 : ‘Hello’, 2 : ‘Hello’, 3 : ‘Hello’, 4 : ‘Hello’, 5 : ‘Hello’}
>>> dic1 = dic.setdefault (‘Muskan’)
(x) copy() >>> print (‘Dictionary :’, dic)
This method returns a shallow copy of the dictionary. Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27, ‘Muskan’ :
None}
Syntax
dict.copy( ) >>> print (‘Founded key : ’ , dic1)
Founded key : None
Here, copy( ) method does not take any parameters.
For example, (xiii) max ()
dic = {1 : ‘One’, 2 : ‘Two’, 3 : ‘Three’} This method is used to return the maximum key from the
dic1 = dic. copy ( ) dictionary.
print (‘Original dictionary : ’, dic) Syntax
print (‘Copied dictionary : ’, dic1) max(dict)
Output For example,
Original dictionary : {1 : ‘One’, 2 : ‘Two’, 3 : ‘Three’} dic = {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
Copied dictionary : {1 : ‘One’, 2 : ‘Two’, 3 : ‘Three’} dic1 = max(dic)
(xi) popitem () print (‘Dictionary : ’, dic)
This method in dictionary helps to achieve similar purpose. print (‘Maximum key : ’, dic1)
It removes the arbitrary key value pair from the dictionary Output
and returns it as a tuple. There is an update for this method Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
from Python version 3.7 onwards.
Maximum key : Shrey
Syntax
dict.popitem( ) (xiv) min ()
For example, This method is used to return the minimum key from the
dic = {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27} dictionary.
print (‘Before deletion : ’, dic) Syntax
dic1 = dic.popitem ( ) min(dict)
print (‘Deleted element’, dic1) For example,
print (‘After deletion :’, dic) dic = {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
Output dic1 = min(dic)
Before deletion : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27} print (‘Dictionary :’, dic)
Deleted element : (‘Shrey’, : 27) print (‘Minimum key :’, dic1)
After deletion : {‘Akshat’ : 26, ‘Riya’ : 24} Output
(xii) setdefault () Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
Minimum key : Akshat
This method returns the value of a key (if the key is in
dictionary). If not, it inserts key with a value to the
dictionary.
Another random document with
no related content on Scribd:
slaughtered in camp and the presents at the end of the journey are
exclusively his. A man guilty of preceding the Pagazi is liable to fine,
and an arrow is extracted from his quiver to substantiate his identity
at the end of the march. Pouring out of the kraal in a disorderly mob,
the porters stack their goods at some tree distant but a few hundred
yards, and allow the late and lazy and the invalids to join the main
body. Generally at this conjuncture the huts are fired by neglect or
mischievousness. The khambi, especially in winter, burns like tinder,
and the next caravan will find a heap of hot ashes and a few charred
sticks still standing. Yet by way of contrast, the Pagazi will often take
the trouble to denote by the usual signposts to those following them
that water is at hand; here and there a little facetiousness appears in
these directions, a mouth is cut in the tree trunk to admit a bit of
wood simulating a pipe, with other representations still more
waggish.
“After the preliminary halt, the caravan forming into the order of
march, winds like a monstrous land serpent over hill, dale, and plain.
The kirangozi is followed by an Indian file; those nearest to him are
heavily laden with ivory. When the weight of the tusk is inordinate it
is tied to a pole and is carried palanquin fashion by two men. The
ivory carriers are succeeded by the bearers of cloth and beads, each
man poising on either shoulder, and sometimes raising upon the
head for rest, packs that resemble huge bolsters, six feet long by two
in diameter, cradled in sticks which generally have a forked
projection for facility in stacking and reshouldering the load. The
sturdiest fellows are usually the lightest loaded in Eastern Africa; as
elsewhere, the weakest go to the wall. The maximum of burden may
be two farasilah, or seventy pounds avoirdupois. Behind the cloth
bearers straggles a long line of porters and slaves laden with the
lighter stuff—rhinoceros teeth, hides, salt, tobacco, brass wire, iron
hoes, boxes and bags, beds and tents, pots and water gourds, mats,
and private stores. With the Pagazi, but in separate parties, march
the armed slaves, who are never seen to quit their muskets; the
women and the little toddling children, who rarely fail to carry
something, be it only of a pound weight; and the asses neatly laden
with saddle-bags of giraffe and buffalo hide. A Mganga also
universally accompanies the caravan, not disdaining to act as a
common porter. The rear is brought up by the master, or the
masters, of the caravan, who often remain far behind for the
convenience of walking and to prevent desertion.
“All the caravan is habited in its worst attire; the East African
derides those who wear upon a journey the cloth which should be
reserved for display at home. If rain fall they will doff the single goat-
skin hung round their sooty limbs and, folding it up, place it between
the shoulders and the load. When grain is served out for a long
march, each porter bears his posho or rations fastened like a large
‘bustle’ to the small of his back. Upon this again he sometimes binds,
with its legs projecting outwards, the three-legged stool, which he
deems necessary to preserve him from the danger of sitting upon the
damp ground. As may be imagined, the barbarians have more
ornament than dress. Some wear a strip of zebra’s mane bound
round the head with the bristly parti-coloured hair standing out like a
saint’s gloria, others prefer a long bit of stiffened ox-tail rising like a
unicorn’s horn at least a foot above the forehead. Other ornaments
are the skins of monkeys and ocelots, roleaus and fillets of white,
blue, or scarlet cloth, and huge bunches of ostrich, crane, and jay’s
feathers crowning the heads like the tufts of certain fowls. Their arms
are decorated with massive ivory bracelets, heavy bangles of brass
and copper, and thin circlets of the same metal, beads in strings and
bands adorn their necks, and small iron bells strapped below the
knee or round the ancle by the more aristocratic. All carry some
weapon; the heaviest armed have a bow and a bark quiver full of
arrows, two or three long spears and assegais, and a little battle-axe,
borne on the shoulder.
“The normal recreations of a march are whistling, singing,
shouting, hooting, horning, drumming, imitating the cries of birds and
beasts, repeating words which are never used except on journeys.
There is gabble enough and abundant squabbling; in fact, perpetual
noise, which the ear, however, soon learns to distinguish for the
hubbub of a halt. The uproar redoubles near a village where the flag
is unfurled and where the line lags to display itself. All give vent to
loud shouts: ‘Hopa, hopa! go on, go on—Mgogolo! a stoppage—
food, food—don’t be tired—the kraal is here—home is near—hasten,
Kirangozi—oh! we see our mothers—we go to eat.’ On the road it is
considered prudent, as well as pleasurable, to be as loud as
possible, in order to impress upon plunderers an exaggerated idea of
the caravan’s strength; for equally good reasons silence is
recommended in the kraal. When threatened with attack, and no
ready escape suggests itself, the porters ground their loads and
prepare for action. It is only self-interest that makes them brave. I
have seen a small cow trotting up with tail erect break a line of 150
men carrying goods not their own. If a hapless hare or antelope
cross the path, every man casts his pack, brandishes his spear, and
starts in pursuit; the animal, never running straight, is soon killed and
torn limb from limb, each hunter devouring his morsel raw. When two
parties meet, that commanded by an Arab claims the road. If both
are Wanyamwezi, violent quarrels ensue; fatal weapons, which are
too ready at hand, are turned to more harmless purposes, the bow
and spear being used as whip and cudgel. These affrays are not
rancorous till blood is shed. Few tribes are less friendly for so trifling
an affair as a broken head; even a slight cut, or a shallow stab, is
little thought of; but if returned with interest great loss of life may
arise from the slenderest cause. When friendly caravans meet, the
two Kirangozis sidle up with a stage pace, a stride and a stand, and
with sidelong looks prance till arrived within distance, then suddenly
and simultaneously ducking, like boys ‘give a back,’ they come to
loggerheads and exchange a butt violently as fighting rams. Their
example is followed by all with a crush which might be mistaken for
the beginning of a faction; but it ends, if there be no bad blood, in
shouts of laughter. The weaker body, however, must yield
precedence and offer a small present as blackmail.”
After all, however, there is some reason in the African’s objection
to be hurried on a march, or to exert himself overmuch in the
interests of a traveller, whose private affairs are nothing to him and
whom, when discharged, he will in all probability never see again. He
does not particularly wish to see him, as he is perfectly comfortable
at home. According to the last quoted authority he rises with the
dawn from his couch of cow’s-hide. The hut is cool and comfortable
during the day; but the barred door, impeding ventilation at night,
causes it to be close and disagreeable. The hour before sunrise
being the coldest time, he usually kindles a fire and addresses
himself to his constant companion the pipe. When the sun becomes
sufficiently powerful, he removes the reed-screen from the entrance
and issues forth to bask in the morning beams. The villages are
populous, and the houses touching one another enable the
occupants, when squatting outside and fronting the central square,
to chat and chatter without moving. About 7 a.m., when the dew has
partially disappeared from the grass, the elder boys drive the flocks
and herds to pasture, with loud shouts and sounding applications of
the quarter staff. They return only when the sun is sinking behind the
western horizon. At 8 p.m. those who have provisions at home enter
the hut to refection with ugali or holcus-porridge, those who have not
join a friend. Pombe, when procurable, is drunk from the earliest
dawn.
After breaking his fast, the African repairs, pipe in hand, to the
Iwanza, the village public previously described. Here in the society of
his own sex he will spend the greater part of the day talking and
laughing, smoking, or torpid with sleep. Occasionally he sits down to
play. As with barbarians generally, gambling in him is a passion. The
normal game is our “heads and tails,” the implement, a flat stone, a
rough circle of tin, or the bottom of a broken pot. The more civilised
have learned the “bas” of the coast, a kind of “tables” with counters
and cups hollowed in a solid plank. Many of the Wanyamwezi have
been compelled by this indulgence to sell themselves into slavery
after playing through their property; they even stake their aged
mothers against the equivalent of an old lady in these lands,—a cow
or a pair of goats. As may be imagined, squabbles are perpetual,
they are almost always, however, settled amongst fellow-villagers
with bloodless weapons. Others, instead of gambling, seek some
employment which, working the hands and leaving the rest of the
body and the mind at ease, is ever a favourite with the Asiatic and
the African; they whittle wood, pierce and wire their pipe sticks—an
art in which all are adepts,—shave one another’s heads, pluck out
their beards, eyebrows, and eyelashes, and prepare and polish their
weapons.
“At about one p.m., the African, unless otherwise employed,
returns to his hut to eat the most substantial and the last meal of the
day, which has been cooked by his women. Eminently gregarious,
however, he often prefers the Iwanza as a dining room, where his
male children, relatives, and friends meet during the most important
hour of the twenty-four. With the savage and the barbarian food is
the all and all of life, food is his thought by day, food is his dream by
night. The civilized European who never knows hunger nor thirst
without the instant means of gratifying every whim of appetite, can
hardly conceive the extent to which his wild brother’s soul is swayed
by stomach; he can scarcely comprehend the state of mental
absorption in which the ravenous human animal broods over the
carcase of an old goat, the delight which he takes in superintending
every part of the cooking process, and the jealous eye with which he
regards all who live better than himself. After eating, the East African
invariably indulges in a long fit of torpidity from which he awakes to
pass the afternoon as he did the forenoon, chatting, playing,
smoking, and chewing sweet earth. Towards sunset all issue forth to
enjoy the coolness; the men sit outside the Iwanza, whilst the
women and the girls, after fetching water for household wants from
the well, collecting in a group upon their little stools, indulge in the
pleasures of gossiping and the pipe. This hour, in the more favoured
parts of the country, is replete with enjoyment. As the hours of
darkness draw nigh, the village doors are carefully closed, and after
milking his cows, each peasant retires to his hut, or passes his time
squatting round the fire with his friends in the Iwanza. He has not yet
learned the art of making a wick, and of filling a bit of pottery with oil.
When a light is wanted he ignites a stick of the oleaginous msásá-
tree—a yellow, hard, close-grained, and elastic wood with few knots,
much used in making spears, bows, and walking staves—which
burns for a quarter of an hour with a brilliant flame. He repairs to his
hard couch before midnight and snores with a single sleep till dawn.
For thorough enjoyment, night must be spent in insensibility, as the
day is in inebriety, and though an early riser he avoids the ‘early to
bed’ in order that he may be able to slumber through half the day.
“Such is the African’s idle day, and thus every summer is spent.
As the wintry rains draw nigh, the necessity of daily bread suggests
itself. The peasants then leave their huts about six or seven a.m.,
often without provision which now becomes scarce, and labour till
noon or two p.m., when they return home, and find food prepared by
the wife or the slave girl. During the afternoon they return to work,
and sometimes, when the rains are near, they are aided by the
women. Towards sunset all wend homeward in a body, laden with
their implements of cultivation, and singing a kind of ‘dulce domum’
in a simple and pleasing recitative.”
Let us conclude this brief sketch of the perils and inconveniences
that menace the explorer of savage shores by presenting the reader
with a picture of the approach of one of the ships bearing some of
the earliest English visitants to the cannibal shores of the Southern
Seas:
“Notwithstanding,” says Mr. Ellis, “all our endeavours to induce the
natives to approach the ship, they continued for a long time at some
distance viewing us with apparent surprise and suspicion. At length
one of the canoes, containing two men and a boy, ventured
alongside. Perceiving a lobster lying among a number of spears at
the bottom of the canoe, I intimated by signs my wish to have it, and
the chief readily handed it up. I gave him in return two or three
middle-size fish-hooks, which, after examining rather curiously, he
gave to the boy, who having no pocket to put them in, or any article
of dress to which they might be attached, instantly deposited them in
his mouth, and continued to hold with both hands the rope hanging
from the ship.
“The principal person in the canoe appeared willing to come on
board. I pointed to the rope he was grasping and put out my hand to
assist him up the ship’s side. He involuntarily laid hold of it, but could
scarcely have felt my grasp when he instantly drew back his hand
and raising it to his nostrils smelt at it most significantly as if to
ascertain with what kind of being he had come in contact. After a few
moments’ pause he climbed over the ship’s side, and as soon as he
had reached the deck our captain led him to a chair on the quarter-
deck, and pointing to the seat signified his wish that he should be
seated. The chief, however, having viewed it for some time, pushed
it aside and sat down on the deck. Our captain had been desirous to
have the chief aboard that he might ascertain from him whether the
island produced sandal-wood, as he was bound to the Marquesas in
search of that article. A piece was therefore procured and shown
him, with the qualities of which he appeared familiar, for after
smelling it and calling it by some name he pointed to the shore.
“While we had been thus engaged, many of the canoes had
approached the ship, and when we turned round a number of the
natives appeared on deck, and others were climbing over the
bulwarks. They were certainly the most savage-looking natives I had
ever seen; and these barbarians were as unceremonious as their
appearance was uninviting. A gigantic, fierce-looking fellow seized a
youth as he was standing by the gangway and endeavoured to lift
him over the deck, but the lad struggling escaped from his grasp. He
then seized our cabin-boy, but the sailors coming to his assistance
and the native finding that he could not disengage him from their
hold, pulled his woollen shirt over his head and was about to leap
into the sea when he was arrested by the sailors. We had a large
ship-dog chained to his kennel on the deck, and although this animal
was not only fearless but savage, yet the appearance of the natives
seemed to terrify him. One of them caught the dog in his arms and
was proceeding over the ship’s side with him, but perceiving him
fastened to his kennel by the chain he was obliged to relinquish his
prize, evidently much disappointed. He then seized the kennel with
the dog in it, when, finding it nailed to the deck, he ceased his
attempts to remove it and gazed round the ship in search of some
object which he could secure. We had brought from Port Jackson
two young kittens; one of these now came up from the cabin, but she
no sooner made her appearance on the deck, than a native,
springing like a tiger on its prey, caught up the unconscious animal
and instantly leaped over the ship’s side into the sea. Hastening to
the side of the deck I looked over the bulwarks and beheld him
swimming rapidly towards a canoe which lay about fifty yards from
the ship. As soon as he had reached this canoe, holding the cat with
both hands, he exhibited it to his companions with evident exultation.
“Orders were given to clear the ship. A general scuffle ensued
between the islanders and the seamen, in which many of the former
were driven headlong into the sea, where they seemed as much at
home as on solid ground; while others clambered over the vessel’s
sides into their canoes. In the midst of the confusion and the
retreating of the natives the dog, which had hitherto slunk into his
kennel, recovered his usual boldness and not only increased the
consternation by his barking, but severely tore the leg of one of the
fugitives who was hastening out of the ship near the spot where he
was chained. The decks were now cleared; but as many of the
people still hung about the shrouds and chains the sailors drew the
long knives with which, when among the islands, they were
furnished, and by menacing gestures, without wounding any,
succeeded in detaching them altogether from the ship. Some of
them seemed quite unconscious of the keenness of the knife, and I
believe had their hands deeply cut by snatching at the blades.”
Boatmen of Rockingham Bay.
The True Word expounded to a Potentate of Western Africa.
PART XI.
RELIGIOUS RITES AND SUPERSTITIONS.

CHAPTER XXVI.
The mysterious “still small voice”—Samoan mythology—The man who
pushed the Heavens up—The child of the Sun—A Figian version
of the “Flood”—The Paradise of the Figian—Lying Ghosts—
Singular case of abduction—The disobedient Naiogabui—All fair
in love and war—The fate of poor Rokoua—The Samoan hades
—Miscellaneous gods of the Samoans—A god for every village—
The cup of truth—Mourning the destruction of a god’s image—
The most fashionable god in Polynesia—Families marked for
human sacrifice—“Tapu” or “tabu”—Its antiquity and wide-spread
influence—Muzzled pigs and blindfolded chickens—Ceremony of
releasing the porkers—Tremendous feast of baked pig—The tapu
in New Zealand—A terrible tinder box—The sacred pole and the
missionaries—The chief’s backbone—The Pakeka and the iron
pot—One of the best uses of tapu—Its general advantages and
disadvantages—Tapu among the Samoans—Witchcraft in New
Zealand—Visit of a European to a “retired” witch—The religion of
the Dayak—“Tapa,” “Tenahi,” “Iang,” and “Jirong”—Warriors’
ghosts—Religious rites and superstitions of the Sea Dayaks—
The great god Singallong Burong—Belief in dreams among the
Sea Dayaks—Story of the stone bull—Of the painted dog.

eligion, as signifying reverence of God and a belief in


future rewards and punishments, may be said to have
no existence among people who are absolutely savage.
Belief in life hereafter is incompatible with non-belief in
the existence of the soul, and difficult indeed would it be
to show a thorough barbarian who did not repudiate that
grand and awful trust. He is too much afraid of the mysterious thing
to confess to being its custodian. Undoubtedly he is quite conscious
of a power within him immensely superior to that which gives motion
to his arms and legs, and invites him to eat when he is hungry. He
“has ears and hears,” and “the still small voice” that speaks all
languages and fits its admonitions to the meanest understanding
bears the savage no less than the citizen company all the day long,
noting all his acts and whispering its approvals and its censures of
them; and when the savage reclines at night on his mat of rushes,
the still small voice is still vigilant, and reveals for his secret
contemplation such vivid pictures of the day’s misdoing, that his
hands ache with so fervently clasping his wooden greegree, and he
is rocked to sleep and horrid dreams with trembling and quaking
fear.
But the savage, while he acknowledges the mysterious influence,
has not the least notion as to its origin. To his hazy mind the word
“incomprehensible” is synonymous with “evil,” and the most
incomprehensible thing to him, and consequently the most evil, is
death. With us it is anxiety as to hereafter that makes death terrible;
with the savage death is detestable only as a gravedigger, a
malicious spirit who snatches him away from the world—where his
children and his wives are, and where tobacco grows, and palm-
trees yield good wine,—who snatches him away from all these good
things and every other, and shuts him in the dark damp earth to
decay like a rotten branch.
Death therefore is, in his eyes, the king of evil, and all minor evils
agents of the king, and working with but one aim though with
seeming indirectness. This it is that makes the savage a miserable
wretch—despite nature’s great bounty in supplying him with food
without reaping or sowing, and so “tempering the wind” that the
shelter of the boughs makes him a house that is warm enough, and
the leaves of the trees such raiment as he requires. Through his
constant suspicion he is like a man with a hundred jars of honey, of
the same pattern and filled the same, but one—he knows not which
—is poisoned. Taste he must or perish of hunger, but taste he may
and perish of poison; and so, quaking all the time, he picks a little
and a little, suspecting this jar because it is so very sweet, and that
because it has a twang of acid, and so goes on diminishing his
ninety-nine chances of appeasing his hunger and living, to level
odds, that he will escape both hunger and poison and die of fright.
Death is the savage’s poisoned honey-pot. He may meet it in the
wind, in the rain; it may even (why not? he has known such cases)
come to him in a sunray. It may meet him in the forest where he
hunts for his daily bread! That bird that just now flitted by so
suddenly and with such a curious cry may be an emissary of the king
of evil, and now hastening to tell the king that there is he—the victim
—all alone and unprotected in the forest, easy prey for the king if he
comes at once! No more hunting for that day though half-a-dozen
empty bellies be the consequence; away with spear and blow-gun,
and welcome charms and fetiches to be counted and kissed and
caressed all the way home—aye, and for a long time afterwards, for
that very bird may still be perched a-top of the hut, peeping in at a
chink, and only waiting for the victim to close his eyes to summon
the grim king once more. In his tribulation he confides the secret of
his uneasiness to his wife, who with affectionate zeal runs for the
gree-gree-man, who, on hearing the case, shakes his head so
ominously, that though even the very leopard-skin that hangs before
the doorway be the price demanded for it, the most powerful charm
the gree-gree-man has to dispose of must be obtained.
It is only, however, to the perfect savage—the Fan and Ougbi of
Central Africa, the Andamaner of Polynesia, and some others—that
the above remarks apply. If we take belief in the soul and its
immortality as the test, we shall find the number of absolute
barbarians somewhat less than at first sight appears; indeed, the
mythological traditions of many savage people, wrapped as they
invariably are in absurdity, will frequently exhibit in the main such
close resemblance to certain portions of our Scripture history as to
fill us with surprise and wonder. Take, for instance, the following
examples occurring in Samoa, furnished by the Rev. George Turner:
“The earliest traditions of the Samoans describe a time when the
heavens alone were inhabited and the earth covered over with water.
Tangaloa, the great Polynesian Jupiter, then sent down his daughter
in the form of a bird called the Turi (a snipe), to search for a resting-
place. After flying about for a long time she found a rock partially
above the surface of the water. (This looks like the Mosaic account
of the deluge; but the story goes on the origin of the human race.)
Turi went up and told her father that she had found but one spot on
which she could rest. Tangaloa sent her down again to visit the
place. She went to and fro repeatedly, and, every time she went up,
reported that the dry surface was extending on all sides. He then
sent her down with some earth, and a creeping plant, as all was
barren rock. She continued to visit the earth and return to the skies.
Next visit, the plant was spreading. Next time it was withered and
decomposing. Next visit it swarmed with worms. And the next time
had become men and women! A strange account of man’s origin.
But how affectingly it reminds one of his end: ‘They shall lie down
alike in the dust, and the worms shall cover them.’
“They have no consecutive tales of these early times; but we give
the disjointed fragments as we find them. They say that of old the
heavens fell down, and that people had to crawl about like the lower
animals. After a time, the arrow-root and another similar plant
pushed up the heavens. The place where these plants grew is still
pointed out, and called the Te’engga-langi, or heaven-pushing place.
But the heads of the people continued to knock on the skies. One
day, a woman was passing along who had been drawing water. A
man came up to her and said that he would push up the heavens, if
she would give him some water to drink. ‘Push them up first,’ she
replied. He pushed them up. ‘Will that do?’ said he. ‘No, a little
further.’ He sent them up higher still, and then she handed him her
cocoa-nut-shell water bottle. Another account says, that a person
named Tütü pushed up the heavens; and the hollow places in a rock,
nearly six feet long, are pointed out as his footprints. They tell about
a man called Losi, who went up on a visit to the heavens. He found
land and sea there, people, houses, and plantations. The people
were kind to him and supplied him with plenty of food. This was the
first time he had seen or tasted taro. He sought for some in the
plantations and brought it down to the earth; and hence they say the
origin of taro. They do not say how he got up and down. When the
taro tree fell, they say its trunk and branches extended a distance of
nearly sixty miles. In this and the following tale we are reminded of
Jacob’s ladder.
“Two young men, named Punifanga and Tafalin, determined one
afternoon to pay a visit to the moon. Punifanga said he knew a tree
by which they could go up. Tafalin was afraid it might not reach high
enough, and said he would try another plan. Punifanga went to his
tree, but Tafalin kindled a fire, and heaped on cocoa-nut shells and
other fuel so as to raise a great smoke. The smoke rose in a dense
straight column, like a cocoa-nut tree towering away into the
heavens. Tafalin then jumped on to the column of smoke, and went
up and reached the moon long before Punifanga. One wishes to
know what they did next, but here the tale abruptly ends, with the
chagrin of Punifanga when he got up and saw Tafalin there before
him, sitting laughing at him for having been so long on the way.
“In another story we are told, that the man came down one
evening and picked up a woman, called Sina, and her child. It was
during a time of famine. She was working in the evening twilight,
beating out some bark with which to make native cloth. The moon
was just rising, and it reminded her of great bread-fruit. Looking up to
it she said, ‘Why cannot you come down and let my child have a bit
of you?’ The moon was indignant at the idea of being eaten, came
forthwith, and took up her child, board, mallet, and all. The popular
superstition of ‘the man in the moon, who gathered sticks on the
Sabbath-day,’ is not yet forgotten in England, and in Samoa, of the
woman in the moon. ‘Yonder is Sina,’ they say, ‘and her child, and
mallet and board.’
“We have a fragment or two, also, about the sun. A woman called
Manquamanqui became pregnant by looking at the rising sun. Her
son grew, and was named ‘Child of the Sun.’ At his marriage he
asked his mother for a dowry. She sent him to his father the Sun, to
beg from him, and told him how to go. Following her directions, he
went one morning, with a long vine from the bush, which is the
convenient substitute for a rope, climbed a tree, threw his rope, with
a noose at the end of it, and caught the Sun. He made his message
known and (Pandora like) got a present for his bride. The Sun first
asked him what was his choice, blessings or calamities? He chose,
of course, the former, and came down with his store of blessings
done up in a basket. There is another tale about this Samoan
Phaeton, similar to what is related of the Hawaiian Mani. They say
that he and his mother were annoyed at the rapidity of the sun’s
course in those days—that it rose, reached the meridian, and set
‘before they could get their mats dried.’ He determined to make it go
slower. He climbed a tree one morning early, and with a rope and
noose all ready, watched for the appearance of the sun. Just as it
emerged from the horizon, he threw, and caught it; the sun struggled
to get clear, but in vain. Then fearing lest it should be strangled, it
called out in distress, ‘Oh! have mercy on me, and spare my life.
What do you want?’ ‘We wish you to go slower, we can get no work
done.’ ‘Very well,’ replied the Sun; ‘let me go, and for the future I will
walk slowly, and never go quick again.’ He let go the rope, and ever
since the sun has gone slowly, and given us longer days. Ludicrous
and puerile as this is, one cannot help seeing in it the wreck of that
sublime description in the book of Joshua, of the day when that man
of God stood in the sight of Israel, and said: ‘Sun, stand thou still
upon Gibeon; and thou, Moon, in the valley of Ajalon. And the Sun
stood still, and the Moon stayed until the people had avenged
themselves upon their enemies.’
“There are but few tales in Samoa in which we can trace the
deluge; nor are these circumstantial as those which obtain in some
other parts of the Pacific. It is the universal belief, however, ‘that of
old, the fish swam where the land now is;’ and tradition now adds,
when the waters abated, many of the fish of the sea were left on the
land, and afterwards were changed into stones. Hence, they say,
there are stones in abundance in the bush and among the mountains
which were once sharks and other inhabitants of the deep.”
The Figians, islanders of the same group, have an advantage
over the Samoans in this last mythological matter of the deluge.
They have at least half-a-dozen versions of the great flood, of which
the two following, furnished by Ellis and Williams, will serve:
“They speak of a deluge which, according to some of their
accounts, was partial, but in others is stated to have been universal.
The cause of the great flood was the killing of Turukana—a favourite
bird belonging to Udengei—by two mischievous lads, the grandsons
of the god. These, instead of apologizing for their offence, added
insolent language to the outrage, and fortifying, with the assistance
of their friends, the town in which they lived, defied Udengei to do his
worst. It is said, that although it took the angry god three months to
collect his forces, he was unable to subdue the rebels, and,
disbanding his army, resolved on more efficient revenge. At his
command the dark clouds gathered and burst, pouring streams on
the devoted earth. Towns, hills, and mountains were successively
submerged; but the rebels, secure in the superior height of their own
dwelling-place, looked on without concern. But when at last the
terrible surges invaded their fortress, they cried for direction to a god,
who, according to various accounts, sent them a shaddock punt, or
two canoes, or taught them to build a canoe themselves. However,
all agree the remnant of the human race was saved: the number was
eighty.”
So says Mr. Williams. Now for a literal translation, furnished by Mr.
Osmond to Mr. Ellis:
“Destroyed was Otaheite by the sea; no man, nor dog, nor fowl
remained. The groves of trees and the stones were carried away by
the wind. They were destroyed, and the deep was over the land. But
these two persons, the husband and the wife (when it came in), he
took up his young pig, she took up her young chickens; he took up
the young dog, and she the young kitten. They were going forth, and
looking at Orofena (the highest hill in the island), the husband said,
‘Up both of us to yonder mountain high.’ The wife replied, ‘No, let us
not go thither.’ The husband said, ‘It is a high rock and will not be
reached by the sea;’ but the wife replied, ‘Reached it will be by the
sea yonder: let us ascend Opitohito, round as a breast; it will not be
reached by the sea.’ They two arrived there. Orofena was
overwhelmed by the waves: Opitohito alone remained and was their
abode. There they watched ten nights; the sea ebbed, and they saw
the two little heads of the mountains in their elevation. When the
waters retired, the land remained without produce, without man, and
the fish were putrid in the holes of the rocks. The earth remained, but
the shrubs were destroyed. They descended and gazed with
astonishment: there were no houses, nor cocoa-nuts, nor palm-
trees, nor bread-fruit, nor grass; all was destroyed by the sea. They
two dwelt together; and the woman brought forth two children, a son
and a daughter. In those days covered was the land with food; and
from two persons the earth was repeopled.”
The Figian believes in a future state of perpetual bliss, but not that
the soul, as soon as it leaves the body, is absolved of all care.
Indeed, according to popular belief, the journey of the soul from
earth to heaven is a very formidable business.
“On the road to Nai Thombothombo, and about five miles from it,
is a solitary hill of hard reddish clay spotted with black boulders,
having on its right a pretty grove, and on the left cheerless hills. Its
name is Takiveleyaiva. When near this spot the disembodied spirit
throws the whale’s tooth, which is placed in the hand of the corpse at
burial, at a spiritual pandanus; having succeeded in hitting this, he
ascends the hill and there waits until joined by the spirits of his
strangled wife or wives. Should he miss the mark he is still supposed
to remain in this solitary resting-place, bemoaning the want of
affection on the part of his wife and friends, who are depriving him of
his expected companions. And this is the lone spirit’s lament: ‘How is
this? For a long time I planted food for my wife, and was also of
great use to her friends. Why, then, is she not allowed to follow me?
Do my friends love me no better than this after so many years of toil?
Will no one in love to me strangle my wife?’
“Blessed at last with the company of his wife or wives, who bear
his train, or sad because of their absence, the husband advances
towards Nai Thombothombo, and, club in hand, boards the canoe
which carries spirits to meet their examiner. Notice of his approach is
given by a paroquet which cries once, twice, and so on, according to
the number of spirits in the canoe, announcing a great number by
chattering. The highway to Mbulu lies through Nambanggatai, which,
it seems, is at once a real and unreal town, the visible part being
occupied by ordinary mortals, while in the unseen portion dwells the
family who hold inquest on departed spirits. Thus the cry of the bird
answers a twofold purpose, warning the people to set open the
doors that the spirit may have a free course, and preventing the
ghostly inquisitors from being taken by surprise. The houses in the
town are built with reference to a peculiarity in the locomotion of
spirits, who are supposed at this stage to pass straight forward:
hence all the doorways are opposite to each other, so that the shade
may pass through without interruption. The inhabitants speak in low
tones, and if separated by a little distance communicate their
thoughts by signs.
“Bygone generations had to meet Samu or Ravuyalo; but as he
died in 1847 by a curious misfortune, his duties now devolve upon
his sons, who, having been long in partnership with their illustrious
father, are quite competent to carry on his office. As it is probable
that the elder son will shortly receive the paternal title, or an
equivalent, we will speak of him as Samuyalo the Killer of Souls. On
hearing the paroquet, Samu and his brothers hide themselves in
some spiritual mangrove bushes just beyond the town and alongside
of the path in which they stick a reed as a prohibition to the spirit to
pass that way. Should the comer be courageous, he raises his club
in defiance of the tabu and those who place it there, whereupon
Samu appears to give him battle, first asking, ‘Who are you, and
whence do you come?’ As many carry their inveterate habit of lying
into another world, they make themselves out to be of vast
importance, and to such Samu gives the lie and fells them to the
ground. Should the ghost conquer in the combat, he passes on to
the judgment seat of Ndengei; he is disqualified for appearing there
and is doomed to wander among the mountains. If he be killed in the
encounter, he is cooked and eaten by Samu and his brethren.
“Some traditions put the examination questions into the mouth of
Samu, and judge the spirit at this stage; but the greater number refer
the inquisition to Ndengei.
“Those who escape the club of the soul-destroyer walk on to
Naindelinde, one of the highest peaks of the Kauvandra mountains.
Here the path of the Mbulu ends abruptly at the brink of a precipice,
the base of which is said to be washed by a deep lake. Beyond this
precipice projects a large steer-oar, which one tradition puts in the
charge of Ndengei himself, but another more consistently in the
keeping of an old man and his son, who act under the direction of
the god. These accost the coming spirit thus: ‘Under what
circumstances do you come to us? How did you conduct yourself in
the other world?’ If the ghost should be one of rank, he answers: ‘I
am a great chief; I lived as a chief, and my conduct was that of a
chief. I had great wealth, many wives, and ruled over a powerful
people. I have destroyed many towns, and slain many in war.’ To this
the reply is, ‘Good, good. Take a seat on the broad part of this oar,
and refresh yourself in the cool breeze.’ No sooner is he seated than
they lift the handle of the oar, which lies inland, and he is thus thrown
down headlong into the deep waters below, through which he passes
to Murimuria. Such as have gained the special favour of Ndengei are
warned not to go out on the oar, but to sit near those who hold it, and
after a short repose are sent back to the place whence they came to
be deified.”
The gods of the Figians would, however, seem to cling with
considerable tenacity to the weaknesses that distinguish the most
ordinary mortals. They quarrel, they fight, and worse still, descend to
act the part of lady-stealers, and this even when the booty is the
daughter of a neighbouring god. The last “pretty scandal” of this
character is related by Mr. Seeman in his recently published work on
Figi:
“Once upon a time there dwelt at Rewa a powerful god, whose
name was Ravovonicakaugawa, and along with him his friend the
god of the winds, from Wairna. Ravovonicakaugawa was leading a
solitary life, and had long been thinking of taking a wife to himself. At
last his mind seemed to be made up. ‘Put mast and sail into the
canoe,’ he said, ‘and let us take some women from Rokoua, the god
of Naicobocobo.’ ‘When do you think of starting?’ inquired his
friends. ‘I shall go in broad daylight,’ was the reply; ‘or do you think I
am a coward to choose the night for my work?’ All things being
ready, the two friends set sail and anchored towards sunset off
Naicobocobo. There they waited, contrary to Figian customs, one,
two, three days without any friendly communication from the shore
reaching them, for Rokoua, probably guessing their intention, had
strictly forbidden his people to take any food to the canoe. Rokoua’s
repugnance, however, was not shared by his household. His
daughter, the lovely Naiogabui, who diffused so sweet and powerful
a perfume, that if the wind blew from the east the perfume could be
perceived in the west, and if it blew from the west it could be

You might also like