
List Manipulation in Python | CBSE Class 11 | Computer Science
Dear Class 11th STUDENTS, ! Welcome to this tutorial of List Manipulation in Python from your CBSE class 11 of Computer Science Syllabus .
In this tutorial, we shall be learning our chapter-6: List Manipulation in Python from Unit 2: Programming and Computational Thinking (PCT-1) as CBSE BOARD suggested to learn about computer system and its organisation to complete this section.
Unit 2: Programming and Computational Thinking (PCT-1)
Chapter 11 : List Manipulation in Python:
- Introduction,
- Indexing,
- List operations (concatenation, repetition, membership and slicing), traversing a list using loops, built-in functions/methods–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.
I advice you to check the latest syllabus given by CBSE Board at its Official website: www.cbseacademic.nic.in
Also, in this tutorial we will covers all necessary topics/concepts required to complete your exams preparations in CBSE classes 11th.
Also, you can Sign Up our free Computer Science Courses for classes 11th and 12th.
NOTE:
- We are also giving some important Questions & Answers for better understanding as well as preparation for your examinations.
- You may also download PDF file of this tutorial from our SHOP for free.
- For your ease and more understanding, we are also giving the video explanation class of each and every topic individually, so that you may clear your topics and get success in your examinations.
INTRODUCTION
The lists in python are containers that are used to store a list of any type. Unlike other variable Python lists are mutable i.e., you 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 is a type of sequence like strings and tuples but it differs from them in the way that lists are mutable but strings and tuples are immutable.
This tutorial is dedicated to basic list manipulation in Python. We shall be talking about creating and accessing lists, various list operations and list manipulation through some built-in functions.
CREATING AND ACCESSING LISTS
A list is a standard data type of Python that can store a sequence of values belonging to any type. The Lists are depicted through square brackets, e.g., following are some lists in Python:
[] # list with no member, empty list
[1, 2, 3] # list of integers
[1, 2, 5, 3. 7, 9] # list of numbers (integers and floating point)
[ ‘a’, ‘b’, ‘c’] # list of characters
[ ‘a’, 1, ‘b’, 3.5, ‘zero’] # list of mixed value types
[ ‘one’, ‘Two’, ‘Three’] # list of strings
Before we proceed and discuss how to create lists, one thing that must be clear is that Lists are mutable (i.e., modifiable) i.e., you can change elements of a list in place. In other words, the memory address of a list will not change even after you change its values. List is one of the two mutable types of Pythons – List and Dictionaries are mutable types; all other data types of Python are immutable.
Creating Lists
To create a list, put a number of expressions in square brackets. That is, use square brackets indicate the start and end of the list, and separate the items by commas. For example:
[ 2, 4, 6]
[‘abc’, ‘def’]
[1, 2.0 3, 4.0]
[ ]
Thus, to create a list you can write in the form given below:
L = [ ]
L = [ value, …]
This construct is known as a list display construct.
Consider some more examples:
- The empty list
The empty list is [ ]. It is the list equivalent of 0 or ‘‘and like them it also has truth value as false. You can also create an empty list as :
L = list ()
It will generate an empty list and name that list as L.
- Long lists
If a list contains many elements, then to enter such long list, you can split it across several lines, like below:
Sqrs = [ 0,1, 4, 9 ,16, 25, 36, 49, 64, 81, 100, 121, 144, 169,
196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625]
Notice the opening square bracket and closing square brackets appear just in the beginning and end of the list.
- Nested lists
A list can have an element in it, which itself is a list. Such a list is called nested list, e.g.,
L 1 = [3, 4, [5, 6], 7]
L1 is a nested list with four elements: 3,4, [5,6] and 7. L1 [2] element is a list [5,6].
Length of L1 is 4 as it counts [5,6] as one element. Also, as L1[2] is a list (i.e., [5,6]),
which means L1[2][0] will give5 and L1 [2][1] will give 6.