Practical No.
6: Write Python program to perform following operations on
Lists: Create list, Access list, Update list (Add item, Remove item), Delete list
1. Write a Python program to sum all the items in a list.
total = 0
list1 = [11, 5, 17, 18, 23]
for ele in range(0, len(list1)):
total = total + list1[ele]
print("Sum of all elements in given list: ", total)
2. Write a Python program to multiplies all the items in a list.
l = [2, 3, 4,5]
product = 1
for item in l:
product = product * item
print("Mutplity each item in a list:",product)
3. Write a Python program to get the largest number from a list.
list1 = [10, 20, 4, 45, 99]
list1.sort()
print("Largest element is:", list1[-1])
OR
list1 = [10, 20, 4, 45, 99,200]
print("Largest element is:", max(list1))
4. Write a Python program to get the smallest number from a list.
list1 = [10, 20, 4, 45, 99]
list1.sort()
print("Smallest element is:", list1[:1])
OR
list1 = [10, 20, 1, 45, 99]
print("Smallest element is:", min(list1))
5. Write a Python program to reverse a list.
lst = [10, 11, 12, 13, 14, 15]
lst.reverse()
print(lst)
6. Write a Python program to find common items from two lists.
l1=[2,3,4,6,8]
l2=[2,5,4,7]
c = [value for value in l1 if value in l2]
print("Common Item from two list:",c)
7. Write a Python program to select the even items of a list.
list1 = [10, 21, 4, 45, 66, 93]
for num in list1:
if num % 2 == 0:
print("Even Numbers:",num, end = " ")