diff --git a/algorithms/strings/anagram_check.py b/algorithms/strings/anagram_check.py index 5c20128..7627400 100644 --- a/algorithms/strings/anagram_check.py +++ b/algorithms/strings/anagram_check.py @@ -1,14 +1,17 @@ -# function to check if two strings are -# anagram or not -def check(s1, s2): - - # the sorted strings are checked - if(sorted(s1)== sorted(s2)): - print("The strings are anagrams.") - else: - print("The strings aren't anagrams.") - -# driver code -s1 ="listen" #String 1 -s2 ="silent" #String 2 -check(s1, s2) \ No newline at end of file +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.") + else: + print("The strings aren't anagrams.") + + +# driver code +s1 = "listen" +s2 = "silent" +check(s1, s2) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy