L5 List Container
L5 List Container
and Practise a p
gan
th u
M u
a n
th
L5 - List container m a n a
R a
• List is a collection of dissimilar data types (mostly used for similar datatype)
h y
at
• lst1 = [10, 20, 300, 400, 50]; lst2 = [‘rat’,a‘cat’,
na p ‘bat’, ‘lion’, ‘tiger’, ‘crocodile’]
u g
uth
• lst3 = [10.5, 22, ‘Antelope’, ‘rabbit’,
th a n 456789, 1, 1, 2, 2, 4, 89.9]
M
n a
m a
• lst4 = [100] * 5 R a
Demo using
at h
a p
gan
th u
u
L5_list_ex_access.py
n M
th a
n a
m a
R a
Demo using
at h
a p
gan
th u
u
L5_list_operations.py
n M
th a
n a
m a
R a
• Given a list, you can apply the following member functions using the object.
• append - at the end h y
pat
a
gan
• remove - the element th u
M u
a n
• pop - removes last item (also removes a particular
a t h item, if given)
a n
a m
• insert - after a certain given position
R
• reverse
• sort - both ascending and descending are available
• count
• index - of a particular item
Demo using
at h
a p
gan
th u
u
L5_list_functions.py
n M
th a
n a
m a
R a
Demo using
at h
a p
gan
th u
u
L5_list_copy_comp.py
n M
th a
n a
m a
R a
• List of lists
h y
at
• List embedding an
a p
u g
uth
• List unpacking (using * operator) th a n M
n a
m a
R a
Demo using
at h
a p
gan
th u
u
L5_list_varieties.py
n M
th a
n a
m a
R a
lst.append(expression)
Demo using
at h
a p
gan
th u
u
L5_list_comprehension.py
n M
th a
n a
m a
R a
L5_list_of_lists_comprehension.py
n M
th a
n a
m a
R a
arr[0] = [1, 2, 3, 4]
arr[1] = [5, 6, 7, 8]