Pract6
Pract6
print(List2)
List2[0]=60
print(List2)
List2[3:4]=70,80
print(List2)
list1.insert(1,30)
print( list1 )
1|Page
Subject: PWP[22616]
Practical No. 6: List Operations
Name: Ritesh Doibale Roll no:41
list=[10,20,30,40,50]
del list[2]
print(list)
print("Using remove operator")
list.remove(50)
print(list)
Output:
2|Page
Subject: PWP[22616]
Practical No. 6: List Operations
Name: Ritesh Doibale Roll no:41
Exercise.
1.Write a Python program to sum all the items in a list
list=[100,400,500,200,700,600]
print(list)
sum=0
for item in list:
sum+=item
print("sum of items is :",sum)
Output:
list=[100,400,500,200,700,600]
print(list)
multiplication=1
for item in list:
multiplication*=item
print("multiplication of items is :",multiplication)
Output:
list=[100,400,500,200,700,600]
print(list)
greater=list[0]
for item in list:
if item>greater:
greater=item
print("Largest no is :",greater)
Output:
3|Page
Subject: PWP[22616]
Practical No. 6: List Operations
Name: Ritesh Doibale Roll no:41
4. Write a Python program to get the smallest number from a list.
list=[100,400,500,200,700,600]
print(list)
smallest=list[0]
for item in list:
if item<smallest:
smallest=item
print("Smallest no is :",smallest)
Output:
list=[100,400,500,200,700,600]
print(list)
rev=list[::-1]
print(rev)
Output:
list1 = [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
set1 = set(list1)
set2 = set(list2)
common_items = list(set1.intersection(set2))
print("Common items: ", common_items)
Output:
4|Page
Subject: PWP[22616]
Practical No. 6: List Operations
Name: Ritesh Doibale Roll no:41
7. Write a Python program to select the even items of a list.
list=[100,402,500,203,707,600]
print(list)
even=[]
for item in list:
if item%2==0:
even.append(item)
print("Even no are :",even)
Output:
5|Page