Skip to content
Open
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
21 changes: 21 additions & 0 deletions strings/check_anagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
str1 = "Race"
str2 = "Care"

# convert both the strings into lowercase
str1 = str1.lower()
str2 = str2.lower()

# check if length is same
if len(str1) == len(str2):
# sort the strings
sorted_str1 = sorted(str1)
sorted_str2 = sorted(str2)

# if sorted char arrays are same
if sorted_str1 == sorted_str2:
print(str1 + " and " + str2 + " are anagram.")
else:
print(str1 + " and " + str2 + " are not anagram.")

else:
print(str1 + " and " + str2 + " are not anagram.")