SlideShare a Scribd company logo
2
Most read
7
Most read
21
Most read
List Manipulation
based on CBSE curriculum
Class 11
By-
Neha Tyagi
PGT CS
KV 5 Jaipur II Shift, Jaipur Region
Neha Tyagi, KV 5 Jaipur II Shift
Introduction
Neha Tyagi, KV 5 Jaipur II Shift
• In Python, a list is a kind of container that contains collection
of any kind of values.
• A List is a mutable data type which means any value from the
list can be changed. For changed values , Python does not
create a new list.
• List is a sequence like a string and a tuple except that list is
mutable whereas string and tuple are immutable.
• In this chapter we will see the manipulation on lists. We will
see creation of list and various operation on lists via built in
functions.
List Creation
Neha Tyagi, KV 5 Jaipur II Shift
• List is a standard data type of Python. It is a sequence which
can store values of any kind.
• List is represented by square brackets “ [ ] “
For ex -
• [ ] Empty list
• [1, 2, 3] integers list
• [1, 2.5, 5.6, 9] numbers list (integer and float)
• [ ‘a’, ‘b’, ‘c’] characters list
• [‘a’, 1, ‘b’, 3.5, ‘zero’] mixed values list
• [‘one’, ’two’, ’three’] string list
• In Python, only list and dictionary are mutable data types, rest
of all the data types are immutable data types.
Creation of List
Neha Tyagi, KV 5 Jaipur II Shift
• List can be created in following ways-
• Empty list -
L = [ ]
• list can also be created with the following statement-
L = list( )
• Long lists-
even = [0, 2, 4, 6, 8, 10 ,12 ,14 ,16 ,18 ,20 ]
• Nested list -
L = [ 3, 4, [ 5, 6 ], 7]
This is tuple
Another method
Creation of List
Neha Tyagi, KV 5 Jaipur II Shift
-As we have seen in the example
That when we have supplied
values as numbers to a list even then
They have automatically converted to string
– If we want to pass values to a list in numeric form then we have to write
following function -
eval(input())
L=eval(input(“Enter list to be added “))
eval ( ) function identifies type of the passed string and then return it.
String Values
Another example
Accessing a List
Neha Tyagi, KV 5 Jaipur II Shift
• First we will see the similarities between a List and a String.
• List is a sequence like a string.
• List also has index of each of its element.
• Like string, list also has 2 index, one for forward indexing (from
0, 1, 2, 3, ….to n-1) and one for backward indexing(from -n to -
1).
• In a list, values can be accessed like string.
0 1 2 3 4 5 6 7 8 9 10 11 12 13
R E S P O N S I B I L I T Y
-14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
Forward index
List
Backward index
Accessing a List
Neha Tyagi, KV 5 Jaipur II Shift
• len( ) function is used to get the length of a list.
• L[ i ] will return the values exists at i index.
• L [ i : j ] will return a new list with the values from i index to j index excluding
j index.
Important 1:membership
operator (in, not in) works
in list similarly as they work
in other sequence.
Important 2: + operator
adds a list at the end of
other list whereas *
operator repeats a list.
Difference between a List and a String
Neha Tyagi, KV 5 Jaipur II Shift
• Main difference between a List and a string is that string is
immutable whereas list is mutable.
• Individual values in string can’t be change whereas it is
possible with list.
Value didn’t
change in string.
Error shown. Value got changed
in list specifying
list is mutable
Traversal of a list
Neha Tyagi, KV 5 Jaipur II Shift
• Traversal of a list means to access and process each and
every element of that list.
• Traversal of a list is very simple with for loop –
for <item> in <list>:
*Python supports UNICODE therefore
output in Hindi is also possible
Comparison of Lists
Neha Tyagi, KV 5 Jaipur II Shift
• Relational operators are used to compare two different lists.
• Python compares lists or tuples in lexicographical order,
means comparing sequences should be of same type and
their elements should also be of similar type.
• In first example, python did not
raise the error because both the
lists are same.
• In second comparison, both the
lists are not similar hence, python
raised the error.
Some
examples
List Operations (+, *)
Neha Tyagi, KV 5 Jaipur II Shift
• Main operations that can be performed on lists are joining list,
replicating list and list slicing.
• To join Lists,+ operator , is used which joins a list at the end of
other list. With + operator, both the operands should be of list
type otherwise error will be generated.
• To replicate a list, * operator , is used.
List Slicing
Neha Tyagi, KV 5 Jaipur II Shift
• To slice a List, syntax is seq = list [ start : stop ]
• Another syntax for List slicing is –
seq=list[start:stop:step]
Use of slicing for list Modification
Neha Tyagi, KV 5 Jaipur II Shift
• Look carefully at following examples-
Here also, new value is being assigned.
New value is being assigned here.
See the difference between both the results.
144 is a value and not a sequence.
List Manipulation
Neha Tyagi, KV 5 Jaipur II Shift
• Element Appending in List list.append(item)
• Updating List elements list[index]=<new value>
• Deletion of List elements del list[index]
Important: if we write del list complete
list will be deleted.
Important: del
command can be
used to delete an
element of the list
or a complete slice
or a complete list.
List Manipulation
Neha Tyagi, KV 5 Jaipur II Shift
• Only one element will be deleted on pop() from list.
• pop ( ) function can not delete a slice.
• pop ( ) function also returns the value being deleted.
list.pop(<index>)
1st item
Last item
6th item
List Functions and Methods
Neha Tyagi, KV 5 Jaipur II Shift
– Python provides some built-in functions for list manipulation
– Syntax is like <list-object>.<method-name>
Function Details
List.index(<item>) Returns the index of passed items.
List.append(<item>) Adds the passed item at the end of list.
List.extend(<list>) Append the list (passed in the form of argument) at the end of list
with which function is called.
List.insert(<pos>,<item>) Insert the passed element at the passed position.
List.pop(<index>) Delete and return the element of passed index. Index passing is
optional, if not passed, element from last will be deleted.
List.remove(<value>) It will delete the first occurrence of passed value but does not
return the deleted value.
List Functions and Methods
Neha Tyagi, KV 5 Jaipur II Shift
Function Details
List.clear ( ) It will delete all values of list and gives an empty list.
List.count (<item>) It will count and return number of occurrences of the passed element.
List.reverse ( ) It will reverse the list and it does not create a new list.
List.sort ( ) It will sort the list in ascending order. To sort the list in descending
order, we need to write----- list.sort(reverse =True).
List Functions and Methods
Neha Tyagi, KV 5 Jaipur II Shift
• List.index ( ) function:
• List.append( ) function:
• List.extend( ) function:
• List.insert( ) function:
List Functions and Methods
Neha Tyagi, KV 5 Jaipur II Shift
• List.pop ( ) function:
• List.remove( ) function:
• List.count( ) function:
List Functions and Methods
Neha Tyagi, KV 5 Jaipur II Shift
• List.reverse( ) function:
• List.sort( ) function:
Important
• To sort a list in reverse order, write in following manner–
List.sort(reverse=True)
• If a list contains a complex number, sort will not work.
Thank you
Please follow us on our blog-
Neha Tyagi, KV 5 Jaipur II Shift
www.pythontrends.wordpress.com

More Related Content

PPTX
Doubly Linked List
PPTX
Stacks IN DATA STRUCTURES
PPT
Queue AS an ADT (Abstract Data Type)
PPTX
Stack and Queue
PPT
Queue data structure
PPTX
Doubly linked list (animated)
PPTX
String Manipulation in Python
PPTX
Stacks and Queue - Data Structures
Doubly Linked List
Stacks IN DATA STRUCTURES
Queue AS an ADT (Abstract Data Type)
Stack and Queue
Queue data structure
Doubly linked list (animated)
String Manipulation in Python
Stacks and Queue - Data Structures

What's hot (20)

PPTX
queue & its applications
PPTX
Unit 3 stack
PPTX
Chapter 15 Lists
PPTX
Presentation on queue
PPSX
Data Structure (Queue)
PDF
Tuples in Python
PPTX
stack & queue
PPTX
Data structures
PPTX
Data types in python
PPTX
Stack & Queue using Linked List in Data Structure
PPTX
Quick sort
PDF
Python revision tour i
PPTX
Inner join and outer join
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
PPTX
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
PDF
Python functions
PPT
Queue implementation
PPTX
Binary search
PPTX
Linked List
PPTX
Python list
queue & its applications
Unit 3 stack
Chapter 15 Lists
Presentation on queue
Data Structure (Queue)
Tuples in Python
stack & queue
Data structures
Data types in python
Stack & Queue using Linked List in Data Structure
Quick sort
Python revision tour i
Inner join and outer join
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Python functions
Queue implementation
Binary search
Linked List
Python list
Ad

Similar to Python list manipulation basics in detail.pdf (20)

PPTX
Python lists
PDF
PDF
Data type list_methods_in_python
PPTX
Lists on the pyhton to learn the children more easily on easy codes.pptx
PPTX
Python _dataStructures_ List, Tuples, its functions
PPTX
Lists.pptx
PDF
Python list functions
DOCX
Python Materials- Lists, Dictionary, Tuple
PDF
List , tuples, dictionaries and regular expressions in python
PPTX
list.pptx
PDF
Lists and its functions in python for beginners
PPTX
Python Lecture 8
PPTX
listppt.pptx h4wtgesvzdfvgsrbyhrrtgsvefcdef
PPT
UNIT 4 PY.ppt - DATA STRUCTURE IN PYTHON
PPTX
Pythonlearn-08-Lists (1).pptxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
PDF
Python lecture 04
PPTX
Unit 4.pptx python list tuples dictionary
PPTX
updated_list.pptx
Python lists
Data type list_methods_in_python
Lists on the pyhton to learn the children more easily on easy codes.pptx
Python _dataStructures_ List, Tuples, its functions
Lists.pptx
Python list functions
Python Materials- Lists, Dictionary, Tuple
List , tuples, dictionaries and regular expressions in python
list.pptx
Lists and its functions in python for beginners
Python Lecture 8
listppt.pptx h4wtgesvzdfvgsrbyhrrtgsvefcdef
UNIT 4 PY.ppt - DATA STRUCTURE IN PYTHON
Pythonlearn-08-Lists (1).pptxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
Python lecture 04
Unit 4.pptx python list tuples dictionary
updated_list.pptx
Ad

More from neonaveen (8)

PPTX
Introduction to C which deals with the basics of C
PPT
introduction to cryptography (basics of it)
PPTX
Digital_signature[1]and its basics .pptx
PPTX
digital signature and its creations.pptx
PPT
VM_2024_21.12.23 final.ppt
PDF
Database Management Systems Question Paper.pdf
PDF
ch01.pdf
PDF
Overview of computers Questions.pdf
Introduction to C which deals with the basics of C
introduction to cryptography (basics of it)
Digital_signature[1]and its basics .pptx
digital signature and its creations.pptx
VM_2024_21.12.23 final.ppt
Database Management Systems Question Paper.pdf
ch01.pdf
Overview of computers Questions.pdf

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Sports Quiz easy sports quiz sports quiz
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Types and Its function , kingdom of life
PDF
Pre independence Education in Inndia.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Structure & Organelles in detailed.
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
master seminar digital applications in india
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Supply Chain Operations Speaking Notes -ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Complications of Minimal Access Surgery at WLH
Anesthesia in Laparoscopic Surgery in India
Sports Quiz easy sports quiz sports quiz
O5-L3 Freight Transport Ops (International) V1.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Types and Its function , kingdom of life
Pre independence Education in Inndia.pdf
01-Introduction-to-Information-Management.pdf
Insiders guide to clinical Medicine.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Structure & Organelles in detailed.
Renaissance Architecture: A Journey from Faith to Humanism
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
master seminar digital applications in india
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Supply Chain Operations Speaking Notes -ICLT Program

Python list manipulation basics in detail.pdf

  • 1. List Manipulation based on CBSE curriculum Class 11 By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region Neha Tyagi, KV 5 Jaipur II Shift
  • 2. Introduction Neha Tyagi, KV 5 Jaipur II Shift • In Python, a list is a kind of container that contains collection of any kind of values. • A List is a mutable data type which means any value from the list can be changed. For changed values , Python does not create a new list. • List is a sequence like a string and a tuple except that list is mutable whereas string and tuple are immutable. • In this chapter we will see the manipulation on lists. We will see creation of list and various operation on lists via built in functions.
  • 3. List Creation Neha Tyagi, KV 5 Jaipur II Shift • List is a standard data type of Python. It is a sequence which can store values of any kind. • List is represented by square brackets “ [ ] “ For ex - • [ ] Empty list • [1, 2, 3] integers list • [1, 2.5, 5.6, 9] numbers list (integer and float) • [ ‘a’, ‘b’, ‘c’] characters list • [‘a’, 1, ‘b’, 3.5, ‘zero’] mixed values list • [‘one’, ’two’, ’three’] string list • In Python, only list and dictionary are mutable data types, rest of all the data types are immutable data types.
  • 4. Creation of List Neha Tyagi, KV 5 Jaipur II Shift • List can be created in following ways- • Empty list - L = [ ] • list can also be created with the following statement- L = list( ) • Long lists- even = [0, 2, 4, 6, 8, 10 ,12 ,14 ,16 ,18 ,20 ] • Nested list - L = [ 3, 4, [ 5, 6 ], 7] This is tuple Another method
  • 5. Creation of List Neha Tyagi, KV 5 Jaipur II Shift -As we have seen in the example That when we have supplied values as numbers to a list even then They have automatically converted to string – If we want to pass values to a list in numeric form then we have to write following function - eval(input()) L=eval(input(“Enter list to be added “)) eval ( ) function identifies type of the passed string and then return it. String Values Another example
  • 6. Accessing a List Neha Tyagi, KV 5 Jaipur II Shift • First we will see the similarities between a List and a String. • List is a sequence like a string. • List also has index of each of its element. • Like string, list also has 2 index, one for forward indexing (from 0, 1, 2, 3, ….to n-1) and one for backward indexing(from -n to - 1). • In a list, values can be accessed like string. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 R E S P O N S I B I L I T Y -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 Forward index List Backward index
  • 7. Accessing a List Neha Tyagi, KV 5 Jaipur II Shift • len( ) function is used to get the length of a list. • L[ i ] will return the values exists at i index. • L [ i : j ] will return a new list with the values from i index to j index excluding j index. Important 1:membership operator (in, not in) works in list similarly as they work in other sequence. Important 2: + operator adds a list at the end of other list whereas * operator repeats a list.
  • 8. Difference between a List and a String Neha Tyagi, KV 5 Jaipur II Shift • Main difference between a List and a string is that string is immutable whereas list is mutable. • Individual values in string can’t be change whereas it is possible with list. Value didn’t change in string. Error shown. Value got changed in list specifying list is mutable
  • 9. Traversal of a list Neha Tyagi, KV 5 Jaipur II Shift • Traversal of a list means to access and process each and every element of that list. • Traversal of a list is very simple with for loop – for <item> in <list>: *Python supports UNICODE therefore output in Hindi is also possible
  • 10. Comparison of Lists Neha Tyagi, KV 5 Jaipur II Shift • Relational operators are used to compare two different lists. • Python compares lists or tuples in lexicographical order, means comparing sequences should be of same type and their elements should also be of similar type. • In first example, python did not raise the error because both the lists are same. • In second comparison, both the lists are not similar hence, python raised the error. Some examples
  • 11. List Operations (+, *) Neha Tyagi, KV 5 Jaipur II Shift • Main operations that can be performed on lists are joining list, replicating list and list slicing. • To join Lists,+ operator , is used which joins a list at the end of other list. With + operator, both the operands should be of list type otherwise error will be generated. • To replicate a list, * operator , is used.
  • 12. List Slicing Neha Tyagi, KV 5 Jaipur II Shift • To slice a List, syntax is seq = list [ start : stop ] • Another syntax for List slicing is – seq=list[start:stop:step]
  • 13. Use of slicing for list Modification Neha Tyagi, KV 5 Jaipur II Shift • Look carefully at following examples- Here also, new value is being assigned. New value is being assigned here. See the difference between both the results. 144 is a value and not a sequence.
  • 14. List Manipulation Neha Tyagi, KV 5 Jaipur II Shift • Element Appending in List list.append(item) • Updating List elements list[index]=<new value> • Deletion of List elements del list[index] Important: if we write del list complete list will be deleted. Important: del command can be used to delete an element of the list or a complete slice or a complete list.
  • 15. List Manipulation Neha Tyagi, KV 5 Jaipur II Shift • Only one element will be deleted on pop() from list. • pop ( ) function can not delete a slice. • pop ( ) function also returns the value being deleted. list.pop(<index>) 1st item Last item 6th item
  • 16. List Functions and Methods Neha Tyagi, KV 5 Jaipur II Shift – Python provides some built-in functions for list manipulation – Syntax is like <list-object>.<method-name> Function Details List.index(<item>) Returns the index of passed items. List.append(<item>) Adds the passed item at the end of list. List.extend(<list>) Append the list (passed in the form of argument) at the end of list with which function is called. List.insert(<pos>,<item>) Insert the passed element at the passed position. List.pop(<index>) Delete and return the element of passed index. Index passing is optional, if not passed, element from last will be deleted. List.remove(<value>) It will delete the first occurrence of passed value but does not return the deleted value.
  • 17. List Functions and Methods Neha Tyagi, KV 5 Jaipur II Shift Function Details List.clear ( ) It will delete all values of list and gives an empty list. List.count (<item>) It will count and return number of occurrences of the passed element. List.reverse ( ) It will reverse the list and it does not create a new list. List.sort ( ) It will sort the list in ascending order. To sort the list in descending order, we need to write----- list.sort(reverse =True).
  • 18. List Functions and Methods Neha Tyagi, KV 5 Jaipur II Shift • List.index ( ) function: • List.append( ) function: • List.extend( ) function: • List.insert( ) function:
  • 19. List Functions and Methods Neha Tyagi, KV 5 Jaipur II Shift • List.pop ( ) function: • List.remove( ) function: • List.count( ) function:
  • 20. List Functions and Methods Neha Tyagi, KV 5 Jaipur II Shift • List.reverse( ) function: • List.sort( ) function: Important • To sort a list in reverse order, write in following manner– List.sort(reverse=True) • If a list contains a complex number, sort will not work.
  • 21. Thank you Please follow us on our blog- Neha Tyagi, KV 5 Jaipur II Shift www.pythontrends.wordpress.com