You are on page 1of 3

Python Programming

Subject Code: 22CAH-635

Student Name: Akshay Bir UID: 22MCI10014


Section/Group: 22MAM-1(A) Semester: 1st
Date of Performance: 12/12/2022 Experiment No. 2.4

1. Aim/Overview of the practical:

Task to be done:
1. Write a program in python to read sort a list of integer elements using the bubble sort method.
Display the sorted element on the screen.

2. Write a program in python to find out the frequency of each element in a list using a dictionary.

1. Result/Output/Writing Summary:

def bubbleSort(arr):
n = len(arr)
swapped = False

for i in range(n-1):
for j in range(0, n-i-1):
if arr[j] > arr[j + 1]:
swapped = True
arr[j], arr[j + 1] = arr[j + 1], arr[j]

if not swapped:
return

arr = [64, 34, 25, 12, 22, 11, 90]

bubbleSort(arr)
print("Sorted array is:")
for i in range(len(arr)):
print("% d" % arr[i], end=" ")

2. Result/Output/Writing Summary:
def CountFrequency(my_list):

freq = {}

for item in my_list:

if (item in freq):

freq[item] += 1

else:

freq[item] = 1

for key, value in freq.items():


print ("% d : % d"%(key, value))

if __name__ == "__main__":

my_list =[1, 1, 1, 5, 5, 3, 1, 3, 3, 1, 4, 4, 4, 2, 2, 2, 2]

CountFrequency(my_list)

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and 5
Performance (Pre Lab Quiz)
2. Worksheet 10
3. Post Lab Quiz 5

You might also like