Check if Two Strings Are Anagrams in Python Using counter()

(Last Updated On: 03/04/2023)

Python Program to Check if Two Strings Are Anagrams Using counter() Function

# Check If Two Strings are Anagram Using counter() function in python
# Python3 program for the above approach from collections import Counter
# function to check if two strings are anagram or not

def check(s1, s2):
	# implementing counter function
	if(Counter(s1) == Counter(s2)):
		print("The strings are anagrams.")
		print("The strings aren't anagrams.")
# driver code
s1 = "listen"
s2 = "silent"
check(s1, s2)


The strings are anagrams.

Leave a Reply

Your email address will not be published. Required fields are marked *