0% found this document useful (0 votes)
11 views4 pages

Practical No. 6 Name:-Riddhi Sandip Sardesai Batch: - T2 Roll No.: - 3241 Operations On List Code

The document contains practical exercises on list operations in Python, including appending, inserting, extending, removing items, and clearing a list. It also includes programs for summing, multiplying, finding the largest and smallest numbers, reversing a list, finding common items between two lists, and selecting even items from a list. Each exercise is accompanied by code snippets and expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Practical No. 6 Name:-Riddhi Sandip Sardesai Batch: - T2 Roll No.: - 3241 Operations On List Code

The document contains practical exercises on list operations in Python, including appending, inserting, extending, removing items, and clearing a list. It also includes programs for summing, multiplying, finding the largest and smallest numbers, reversing a list, finding common items between two lists, and selecting even items from a list. Each exercise is accompanied by code snippets and expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical No.

Name :- Riddhi Sandip Sardesai Batch :- T2 Roll No. :- 3241

Operations on List

Code :-

a=[10,20,30,40,"hi"]
print("List : ",a)
a.append(50)
print("After Adding 50 into list using append : ",a)
a.insert(60,5)
print("After inserting 60 into list at index 5 : ",a)
b=[70,80]
a.extend(b)
print("After adding list b into list a : ",a)
a.remove(10)
print("After removing 10 from list a : ",a)
a.pop(4)
print("After removing value at index 4 from list a : ",a)
del a[2]
print("After removing value at index 2 from list a : ",a)
print("Length of list a : ",len(a))
a.clear()
print("After clearing list a : ",a)

Output :-
Exercise

1. Write a python program to sum all items in a list.

Code :-

a=[10,20,30,40,50]
sum=0
print("List a : ",a)
for i in a:
sum=sum+i
print("Sum of all items in list a is : ",sum)

Output :-

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

Code :-

a=[1,2,3,4,5]
mul=1
print("List a : ",a)
for i in a:
mul=mul*i
print("Multiplication of all items in list a is : ",mul)

Output :-

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

Code :-

a=[1,2,3,4,5]
print("List a : ",a)
print("Largest number from list a is : ",max(a))
Output :-

4. Write a python program to get the smallest number from a list.

Code :-

a=[1,2,3,4,5]
print("List a : ",a)
print("Smallest number from list a is : ",min(a))

Output :-

5. Write a python program to reverse a list.

Code :-

a=[10,20,30,40,50]
print("List a : ",a)
a.reverse()
print("After reversing list a : ",a)

Output :-

6. Write a python program to find common items from two list.

Code :-

a=[20,16,34,18,'hello']
b=[16,18,'hello',10]
c=[]
print("List a : ",a)
print("List b : ",b)
for i in a:
for j in b:
if i==j:
c.append(i)
print("Common items from list a and b : ",c)

Output :-

7. Write a python program to select the even items of a list.

Code :-

a=[20,16,34,18,'hello']
print("List a : ",a)
l=len(a)
for i in range(0,l):
if i%2==0:
print("a[",i,"] : ",a[i])

Output :-

You might also like