0% found this document useful (0 votes)
22 views

Pract6

The document discusses list operations in Python including creating, accessing, updating, combining, repeating, inserting, deleting, summing, multiplying, finding largest/smallest numbers, reversing, and finding common items between two lists. Examples and outputs of Python code for each operation are provided.

Uploaded by

Ritesh Doibale
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)
22 views

Pract6

The document discusses list operations in Python including creating, accessing, updating, combining, repeating, inserting, deleting, summing, multiplying, finding largest/smallest numbers, reversing, and finding common items between two lists. Examples and outputs of Python code for each operation are provided.

Uploaded by

Ritesh Doibale
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/ 5

Subject: PWP[22616]

Practical No. 6: List Operations


Name: Ritesh Doibale Roll no:41
Implementation:

print("list create operation")


List1=['Java','Python','Perl']
List2=[10,20,30,40,50]
print("Created list List1:",List1,"\t list2:",List2)

print("\nlist access operation")


print(List2)
print(List2[1])
print(List2[1:3])

print("\nlist update operation")

print(List2)
List2[0]=60
print(List2)
List2[3:4]=70,80
print(List2)

print("\nUdating via using the append and extend:")


list1=[10,20,30]
print( list1 )
list1.append(40)
print( list1 )
list1.extend([60,70])
print( list1 )

print("\nlist combine operation")


list1=[10,20,30]
print(list1 )
print(list1+[40,50,60])

print("\nlist repeat operation")


list2 =['A', 'B']
print(list2 *2 )

print("\nlist insert at operation")


print( list1 )

list1.insert(1,30)
print( list1 )

print("\nlist delete operation")


print("Using del operator")

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:

2. Write a Python program to multiplies all the items in a list.

list=[100,400,500,200,700,600]
print(list)
multiplication=1
for item in list:
multiplication*=item
print("multiplication of items is :",multiplication)
Output:

3. Write a Python program to get the largest number from a list.

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:

5. Write a Python program to reverse a list.

list=[100,400,500,200,700,600]
print(list)
rev=list[::-1]
print(rev)
Output:

6. Write a Python program to find common items from two lists.

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

You might also like