Skip to player
Skip to main content
Search
Connect
Watch fullscreen
Like
Bookmark
Share
More
Add to Playlist
Report
9 - List Function & Methods
Extramarks (Old)
Follow
6 months ago
Category
📚
Learning
Transcript
Display full video transcript
00:00
List functions and methods.
00:11
Concepts discussed in this topic are
00:13
Introduction to operations on lists
00:16
Appending elements to a list
00:19
Updating elements to a list
00:21
Deleting elements from a list
00:23
List functions and methods
00:26
Recapitulation of the topic
00:30
Python provides methods that operate on lists.
00:33
Many of these methods modify the list.
00:36
We can perform various operations
00:38
such as appending, updating, deleting, etc.
00:44
Appending elements to a list means
00:46
adding elements to an existing sequence.
00:49
The append, extend and insert methods
00:53
add items to the list.
00:56
The append method adds a single item
00:59
to the end of the list.
01:01
The extend method adds items from another list
01:04
or any sequence to the end.
01:07
The insert method inserts an item
01:09
at a specific position
01:11
as indicated by the index number
01:13
and moves the remaining items to the right.
01:18
Updating an element of the list
01:19
is accomplished by assessing the elements
01:22
and modifying its value in place.
01:25
We can update a single element
01:27
or part of the list.
01:31
There are several ways to remove elements
01:33
from a list.
01:35
If index is known,
01:36
we can use pop method
01:38
or del statement.
01:40
If the element or elements
01:41
to be deleted is known,
01:43
then remove method can be used.
01:45
To remove multiple elements,
01:47
we can use del statement
01:49
with the list slicing.
01:51
Using assignment operator
01:53
The list manipulation methods
01:57
such as index, append, pop, extend,
02:01
insert, remove, delete
02:03
can be applied to list
02:05
as per following syntax.
02:07
List object dot method name
02:09
The dot operator is used
02:12
to access built-in methods
02:13
of list objects.
02:15
The index method
02:18
returns the index
02:19
of first matched items
02:20
from the list.
02:22
In the given example,
02:24
the method returns
02:25
the index of first value,
02:27
15,
02:28
even if there is another 15
02:29
in the list.
02:31
If the element is not in the list,
02:33
an error will be raised.
02:37
The append method
02:39
adds an item
02:39
to the end of the list
02:41
and returns no value.
02:43
For example,
02:44
to add one more fruit
02:46
in a list containing fruits,
02:48
use append method.
02:50
We see from this example
02:51
that append method
02:52
does not return the new list,
02:55
just modifies the original one.
02:58
The extend method
03:00
is used for adding
03:01
multiple items to a list.
03:03
This method
03:04
takes a list
03:05
as an argument
03:06
and appends
03:07
all of the elements
03:08
of the argument list
03:09
to the list object
03:10
on which this method
03:11
is applied.
03:12
The insert method
03:15
is used
03:16
to insert an item
03:17
at a given position.
03:19
The syntax
03:19
is given here.
03:21
The method
03:22
takes two arguments,
03:23
index of the element
03:24
and the element
03:25
to be inserted.
03:27
It returns no value.
03:30
L1 contains odd numbers
03:32
between 1 to 10,
03:34
but digit 7
03:35
is missing in the list.
03:36
Insert digit 7
03:38
before digit 9
03:39
in the list.
03:41
Now,
03:42
here is the time
03:42
to test your knowledge.
03:46
There are two ways
03:47
of using the pop method.
03:49
The first,
03:50
with no parameter,
03:51
will remove
03:52
and return
03:52
the last item
03:53
of the list.
03:54
The second,
03:55
if you provide
03:56
a parameter
03:57
for the position,
03:58
pop will remove
03:59
and return
04:00
the item
04:00
at that position.
04:03
The pop method
04:04
is used
04:05
to remove
04:05
an item
04:06
from the list.
04:07
The method
04:07
removes an element
04:08
from the given
04:09
position in the list
04:10
and returns
04:11
the removed value.
04:14
The remove method
04:15
removes the first occurrence
04:16
of given item
04:17
from the list.
04:19
The syntax
04:19
is given here.
04:25
The remove method
04:27
raises an error
04:27
if we try to remove
04:29
an element
04:29
which is not present
04:31
in the list.
04:34
We have pop method
04:36
to remove any element
04:37
from the list.
04:38
Then why remove method
04:39
is used?
04:41
Pop method
04:41
removes an element
04:42
whose position
04:43
is given.
04:45
If the index
04:45
or position
04:46
is not known,
04:47
we only know
04:48
the value,
04:49
then remove method
04:50
is used.
04:52
The clear method
04:53
removes all the items
04:55
from the list
04:56
and the list
04:56
becomes empty.
04:59
Del statement
05:00
deletes all the elements
05:02
and the list object too.
05:03
Unlike del statement,
05:05
clear method
05:06
removes only
05:07
the elements
05:08
and not the list element.
05:10
After clear,
05:11
the list object
05:12
still exists
05:13
as an empty list.
05:16
The count method
05:17
returns the count
05:18
of the item
05:19
that is passed
05:20
as an argument.
05:23
What if the argument
05:25
in the count method
05:26
does not exist
05:27
in the list?
05:28
The method
05:29
returns 0.
05:30
The reverse method
05:36
reverses the items
05:37
of the list
05:38
and does not
05:38
return anything.
05:43
Does the reverse method
05:45
create a new list?
05:47
No.
05:47
It does not create
05:48
a new list,
05:49
just reverses the list.
05:53
The sort method
05:54
sorts the items
05:55
of the list
05:56
by default
05:57
in ascending order.
05:58
It does not
05:59
create a new list.
06:01
It does not
06:02
return anything.
06:04
Write a code
06:05
to sort the list
06:06
in decreasing order.
06:08
To sort the list
06:09
in decreasing order,
06:11
set reverse
06:11
is equal to true.
06:15
The following table
06:17
provides a summary
06:18
of the list methods.
06:20
Append method
06:21
adds a new item
06:22
to the end
06:23
of a list.
06:24
Insert method
06:25
inserts a new item
06:27
at the position given.
06:29
Pop method
06:30
without parameters
06:31
removes and returns
06:32
the last item.
06:34
Pop method
06:35
with position
06:36
removes and returns
06:37
the item at position.
06:39
Sort method
06:40
modifies a list
06:42
to be sorted.
06:43
Reverse method
06:44
modifies a list
06:45
to be in reverse order.
06:48
Index method
06:49
returns the position
06:50
of first occurrence
06:51
of item.
06:53
Count method
06:53
returns the number
06:55
of occurrences
06:55
of item.
06:57
Remove method
06:58
removes the first
07:00
occurrence of item.
07:02
Find the errors
07:04
in the given code.
07:05
The method
07:06
is trying to remove
07:07
the element
07:08
which does not exist
07:09
in the list,
07:10
so the error
07:11
is raised.
07:13
Test your knowledge
07:14
of Python functions.
07:16
Match the appropriate
07:17
list method
07:18
to perform
07:18
the following tasks.
07:20
Lesson
07:21
points
07:21
3
07:21
iyim
07:22
6
07:22
1
07:22
2
07:23
2
07:24
2
07:24
1
07:24
2
07:25
2
07:25
3
07:26
2
07:26
3
07:26
3
07:27
4
07:27
...
07:27
3
07:28
4
07:29
4
07:30
5
07:30
5
07:31
5
07:32
6
07:32
5
07:32
4
07:33
6
07:34
5
07:35
6
07:35
7
07:36
10
07:36
7
07:37
7
07:38
8
07:38
8
07:38
9
07:39
9
07:40
9
07:40
9
07:42
10
07:43
8
07:43
10
07:44
20
07:44
7
07:45
9
07:45
10
07:45
12
07:46
11
07:47
10
07:48
11
07:48
10
07:48
11
07:49
You
Be the first to comment
Add your comment
Recommended
10:07
|
Up next
9 - Working With List
Extramarks (Old)
6 months ago
9:10
8 - Getting Started With Python
Extramarks (Old)
6 months ago
16:42
10 - Online Access To Computer Security
Extramarks (Old)
6 months ago
16:38
12 - Introducing DBMS
Extramarks (Old)
6 months ago
9:34
7 - Working With Dictionaries
Extramarks (Old)
6 months ago
7:52
7 - Dictionaries
Extramarks (Old)
6 months ago
6:38
11 - Python Fundamentals I
Extramarks (Old)
6 months ago
9:50
6 - Debugging Programs
Extramarks (Old)
6 months ago
6:19
11 - Python Fundamentals II
Extramarks (Old)
6 months ago
19:04
2 - Basics of computer system
Extramarks (Old)
6 months ago
8:02
3 - Statements In Python
Extramarks (Old)
6 months ago
13:05
5 - Operators
Extramarks (Old)
6 months ago
15:17
4 - Cyber Security
Extramarks (Old)
6 months ago
10:32
1 - Data Representation
Extramarks (Old)
6 months ago
11:11
5 - Expressions
Extramarks (Old)
6 months ago
9:57
5 - Data Types
Extramarks (Old)
6 months ago
5:08
3 - Conditional Statements
Extramarks (Old)
6 months ago
7:20
3 - Iterative Statements
Extramarks (Old)
6 months ago
5:48
1 - Boolean Algebra
Extramarks (Old)
6 months ago
0:51
Former Aide Claims She Was Asked to Make a ‘Hit List’ For Trump
Veuer
2 years ago
1:08
Musk’s X Is ‘the Platform With the Largest Ratio of Misinformation or Disinformation’ Amongst All Social Media Platforms
Veuer
2 years ago
4:50
59 companies that are changing the world: From Tesla to Chobani
Fortune
2 years ago
0:46
3 Things to Know About Coco Gauff's Parents
People
2 years ago
0:35
8 Things to Do in the Morning to Improve Productivity
Martha Stewart Living
2 years ago
2:11
Why You Should Remember Aretha Franklin
Goalcast
2 years ago
Be the first to comment