list manipulation in python class 11 notes

Contents show

list manipulation in python

class 11 notes

list manipulation in python class 11 notes

(list manipulation in python)


the python lists are containers that are used to store a list of values of any type. Unlike other variables python lists are mutable i.e., you can can change the elements of a list in place; python will not create a fresh list when you make changes to an element of a list.


list are mutable sequence of python i.e., you can change elements of a list in place.

Creating and Accessing lists:-

1. []                                        list with no number, empty list

2. [1,2,3]                              list of integer

3. [1,2,5,3.4,7,9]                list of number(integer and floating point)

4. [a, b, c]                             list of character

5. [‘one’, ‘two’, ‘three’]      list of strings

Creating lists




L=list(input(‘enter list elements : ‘))

enter list elements: 234567




>>>L=eval(input(“enter list to be added : “))

enter list elements: [2,3,4,5,6,7]



Nested lists:-


list manipulation in python class 11 notes

Accessing lists:-

  • length:

function len(L) returns the number of items (count) in the list L.

  •  indexing and slicing:

L[i] returns the item at index i(the first item has index 0), and

L[i:j] returns a new list, containing the objects at indexes between i and j (excluding index j).

  •  membership operators

both ‘in’ and ‘not in’ operator work on lists just like they work for other sequences.

that is, in tells if an element is present in list or not, and not in does the opposite.

  •  concatenation and replication operator + and * :-

the + operator adds one list to the end of another. The * operator repeats a list. We shall be talking about these two operations in a later section 7.3 – list operations.

Accessing individual elements:-

>>>vowels=[‘a’,’e’,’i’,’o’, ‘u’]





Difference from strings:-

although lists are similar to strings in many ways, yet there is an important difference in mutability of the two. Strings are not mutable, while list are. You cannot change individual elements of a string place, but lists allow you to do so. That is, following statement is fully valid for lists(though not for strings):



[‘A’, ‘e’,’i’,’o’, ‘u’]

Traversing a list:-

L=[‘p’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]

for a in L:


The above loop will produce result as:







list manipulation in python


Lists in Python Tutorial

list manipulation in python class 11 programs practice more questions

Q 1. program to print elements of list[‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’] in separate lines along with element’s both indexes (positive and negative)

ans.  L=[‘q’, ‘w’, ‘e’, ‘r’, ‘t’, ‘y’]


for a in range(length):

print(“At indexes”, a, “and”,(a-length),”element :”,L[a])

           Sample run above program is :

1. At indexes 0 and -6 element : q

2. At indexes 1 and -5 element : w

3. At indexes 2 and -4 element : e

4. At indexes 3 and -3 element : r

5. At indexes 4 and -2 element : t

6. At indexes 5 and -1 element : y

Q2. Program to find minimum element from a list of element along with its index in list.

program :-

lst = eval(input("Enter list :"))
length = len(lst)
min_ele = lst[0]
min_index = 0
for i in range(1, length-1) :
      if lst[i] < min_ele :
           min_ele = lst[i]
           min_index = i
print("Given list is :", lst)
print("The minimum element of the given list is:")
print(min_ele, "at index", min_index)

Sample run of above program is :

Enter list : [2, 3, 4, -2, 6, -7, 8, 11, -9, 11] Given list is : [2, 3, 4, -2, 6, -7, 8, 11, -9, 11] The minimum element of given list is : -9 at index 8

Comparing lists:-

we can compare two lists using standard comparison operator of python, i.e.,<,>,==,!=, etc.

consider following examples :

1. >>>L1,l2=[1,2,3],[1,2,3]

2. >>>L3=[1,[2,3]]

3. >>>L1==L3


4. >>>L1==L22


list manipulation in python class 11 notes

List operations:-

(1) joining lists

1. >>>lst1=[1,3,5]

2. >>>lst2=[6,7,8]

3. >>>lst1 + lst2

(2)Repeating or Replicating:-

1. >>>lst1*3


(3)Slicing the lists


consider the following example:

1. >>>lst=[10,12,14,20,22,24,30,32,34]

2. >>>seq=lst[3:-3]

3. >>>seq













Working with lists:-


consider some example:

1. >>>lst1=[10,12,14]

2. >>>lst1.append(16)

3. >>>lst1


updating element to a list

L[index]=<new value>

consider following example:

1. >>>lst1=[10,12,14,16]

2. >>>lst1[2]=24

3. >>>lst1


Deleting elements from a list:-

del list[<index>]

del list[<start>:<stop>]

consider following example:


>>>del lst[10]



you can also use pop() method to remove single element.


return the removed item

consider the example below:






the pop() method is useful only when you want to store the element being deleting for later use, e.g.,

item1=L.pop()                 # last item

item2=L.pop(0)               #first item

item3=L.pop(5)               #sixth item

List functions and methods:-

<Listobject>.<method name>()

(1)the index method:-

return index of first matched item


for example:




(2) the append method:-

this method adds an item to the end of the list.


for example:





(3) the extend method:-

the extend() method is also used for adding multiple elements to a list.


consider following example:








Difference between append() and extend()

while append() function adds one element to list, extend can add multiple elements from a list supplied to it as argument.

the extend() cannot add a single element; it require a list as argument.

(4) the insert method:-

the insert() method is also an insertion method for lists, like append and extend methods. However, both append() and extend() insert element(s) at the end of the list. if you wants to insert an element somewhere in between or any position of your choice, both append() and extend() are of no use. For such requirement insert() is used.


the first argument <pos> is the index of the element before which the second argument <item> is to be added.

consider the following example:





(5) the pop method:-


>>>t1=[‘k’,’a’,’e’,’i’,’p’, ‘q’, ‘u’]




(6) the remove method:-

the remove() method removes the first occurrence of given item in the list.

consider following example:

>>>t1=[‘a’,’e’,’i’,’p’, ‘q’, ‘a’, ‘q’, ‘p’]







(7) the clear method:-






[ ]

(8) the count method:-








(9) the reverse method:-






(10) the sort method:-







for decreasing order using sort


Important Questions

Q 1. How are lists different from strings when both are sequences ?
ans. The lists and strings are different in following ways :

1.  The lists are mutable sequences while strings are immutable.
2.  In consecutive locations, strings store the individual character while list stores the references of its elements.
3.  Strings store single type of elements – all character while list can store elements belonging of its elements.
4. Strings store single type of elements – all character while lists can store elements belonging to different types.

Q 2.What are nested lists ?

ans. When a list is contained in another list as a member-element, it is called nested list, e.g.,
a = [2, 3, [4, 5]]
The above list a has three elements – an integer 2, an integer 3 and a list[4, 5], hence it is nested list.

Q 3. What does each of the following expression evaluate to ?
ans. Suppose that L is the list
[“These”, “are”, “a”, [“few”, “words”], “that”, “we”, “will”, “use”]
(a) 1.  L[3:4]
2. L[3:4][0]
3. L[3:4][0][1]
4. L[3:4][0][1][2]

(b) “few” in L
(c) “few” in L[3]
(d) [L[1]] + L[3]
(e) L[4:]
(f) L[0::2]

(a) [[“few”, “words”]]
[“few”, “words”]
(b) False
(c) True
(d) [‘are’, ‘few’, ‘words’]
(e) [“that”, “we”, “will”, “use”]
(f) [“these”, “a”, “that”, “will”]

Q 4. Write the most appropriate list method to perform the following task.
(a) Delete a given element from the list.
(b) Delete 3rd element from the list.
(c) Add an element in the end of the list.
(d) Add an element in the beginning of the list.
(e) Add elements of a list in the end of a list.

(a) remove()
(b) pop()
(c) append()
(d) insert()
(e) extend()

Q 5. L is a non-empty list of ints. Print the smallest and largest integers in L. Write the code without using a loop.

Length = len(L)
Print(“smallest :”, L[0])
print(“largest :”, L[length-1])

list manipulation notes downloadpdf

How to Learn Python for beginners ?