0% found this document useful (0 votes)
844 views2 pages

PWP Practical No. 6

This document provides examples of Python programs to perform common operations on lists: 1. Summing, multiplying, finding the largest and smallest values in lists using for loops and built-in functions. 2. Reversing a list using the list.reverse() method. 3. Finding common items between two lists using a list comprehension. 4. Selecting even numbers from a list using a for loop and modulo operator.

Uploaded by

Rutuja Bhagat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
844 views2 pages

PWP Practical No. 6

This document provides examples of Python programs to perform common operations on lists: 1. Summing, multiplying, finding the largest and smallest values in lists using for loops and built-in functions. 2. Reversing a list using the list.reverse() method. 3. Finding common items between two lists using a list comprehension. 4. Selecting even numbers from a list using a for loop and modulo operator.

Uploaded by

Rutuja Bhagat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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 = " ")

You might also like