1. Write simple Python program to perform
following operations on List:Create
list,Access list,update list(add and remove
item),delete list
PRACTICAL NO 6
2. 1. When to used list
List is used to save a collection of values of same
type in a variable and list support indexing.
5. 4.Write a syntax for a method to count occurences
of a list item in python.
6. 5.How to concatenate list
The '+' operator can be used to concatenate two
lists. It appends one list at the end of the other list
and results in a new list as output.
Syntax
List3=List1+List2
7. 6. Justify the statement “List are mutable”
The value of any element inside the List can be
changed at any point of time.
The Elements of the List are accessible with their
index value.The index always start with 0 and ends
with n-1,if the list contains n elements.
Example
List1=[10,20,30,40]
List1[2]=50
print(List1)
Output
[10, 20, 50, 40]
8. 7. Describe the use of pop operator in list
If we know the index of the element that we want to
delete ,then we can use pop statement.
For Example
list=[10,20,30,40]
list.pop(3)
print(list)
output
[10, 20, 30]
9. 1. Write a python program to sum all the items in a
list.
l=[6,4,9,7,3]
sum=0
for i in l:
sum=sum+i
print("Sum of elements ",l," is ",sum)
Output
Sum of elements [6, 4, 9, 7, 3] is 29
10. 2. Write a python program to multiplies all the items
in a list
l=[2,5,3,1]
sum=1
for i in l:
sum=sum*i
print("Multiplies of elements ",l," is ",sum)
Output
Multiplies of elements [2, 5, 3, 1] is 30
11. 3. Write a program to get the largest number from
list
l=[2,6,98,7,67,1,9,54]
m=0
for i in l:
if(m<i):
m=i
print("LARGEST eLEMENT IN THE lIST=",m)
Output
LARGEST eLEMENT IN THE lIST= 98
12. 4. Write a program to get the smallest number
from list
l=[2,6,98,7,67,1,9,54]
m=l[0]
for i in l:
if(m>i):
m=i
print("SMALLEST ELEMENT=",m)
Output
SMALLEST ELEMENT= 1
13. 5. Write a program to reverse a list.
l1=[1,2,3,4,5]
print("Before reversing ",l1)
l1.reverse()
print("After reversing ",l1)
Output
Before reversing [1, 2, 3, 4, 5]
After reversing [5, 4, 3, 2, 1]
14. 6. Write a program to find common items from two list
l1=[2,5,3,8,9]
l2=[4,1,2,6,8]
l=len(l1)
print("common elements ARE ")
for i in range(0,l):
for j in range(0,l):
if(l1[i]==l2[j]):
print(l1[i])
Output
common elements ARE
2
8
15. 7. Write a program to select the even items of a list.
l=[3,2,5,6,4,8]
print("Are the even numbers from the list")
for i in l:
if(i%2==0):
print(i)
Output
Are the even numbers from the list
2
6
4
8