You are on page 1of 3

Lap Task 3

Objective: To apply algorithms to solve the given problem and implement a modular program using
a method for solving the problem.

Program Code:

#defining a function to check if the two strings are anagrams

Def isAnagram(str1, str2):

#converting str1 into list1

list1=list()

for i in str1:

list1.append(i)

#converting str2 into list2

list2=list()

for i in str2:

list2.append(i)

#sorting the lists

list1.sort()

list2.sort()

#checking if the lists are equal; if equal, they are anagrams, else not

if(list1==list2):

print ("Yes")

else:

print ("No")

#reading the number of pairs of input strings

N = int(input())

#reading each pair into a list


input_list=list()

for i in range(N):

ip=input()

input_list.append(ip)

#splitting each pair and then calling the isAnagram function

print("Output:")

for i in input_list:

lst = i.split()

isAnagram(lst[0], lst[1])
Sample Output:

You might also like