Skip to content

Created check_anagrams.py in strings #2339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions strings/check_anagrams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def check_anagrams(a: str, b: str) -> bool:
"""
Two strings are anagrams if they are made of the same letters
arranged differently (ignoring the case).
>>> check_anagrams('Silent', 'Listen')
True
>>> check_anagrams('This is a string', 'Is this a string')
True
>>> check_anagrams('There', 'Their')
False
"""
return sorted(a.lower()) == sorted(b.lower())


if __name__ == "__main__":
input_A = input("Enter the first string ").strip()
input_B = input("Enter the second string ").strip()

status = check_anagrams(input_A, input_B)
print(
f"{input_A} and {input_B} are {'' if status else 'not '}anagrams."
)