FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactored the code to reduce time complexity by SwayamSahu · Pull Request #148 · AllAlgorithms/python · GitHub

This repository was archived by the owner on Sep 7, 2025. It is now read-only.
/ python Public archive
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
31 changes: 17 additions & 14 deletions algorithms/strings/anagram_check.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -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)
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)

Back | FazBrowse Home | New Git URL