mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Created check_anagrams.py in strings (#2339)
* Add files via upload * Update check_anagrams.py * Update check_anagrams.py * Update check_anagrams.py * Update check_anagrams.py * “” or not Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
9351889fda
commit
2eca71663b
22
strings/check_anagrams.py
Normal file
22
strings/check_anagrams.py
Normal file
@ -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."
|
||||
)
|
Loading…
Reference in New Issue
Block a user