Skip to content

Commit f42902d

Browse files
authored
Merge pull request #5 from Utsav1999/utsav-python
all updates done
2 parents a18e87f + a6ca9b2 commit f42902d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

strings/anagram_check.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
== Anagram Check ==
3+
An anagarm is a word/ phrase that can be formed by rearranging
4+
the characters of another word/ phrase, typically using each
5+
character only once.
6+
for example, firstWord = listen, secondWord = silent
7+
return value will be True.
8+
https://en.wikipedia.org/wiki/Anagram
9+
"""
10+
11+
12+
def anagram(firstWord: str, secondWord: str) -> bool:
13+
"""
14+
>>> anagram(listen, silent)
15+
True
16+
>>> anagram(rat, bat)
17+
False
18+
>>> anagram(tool, loot)
19+
True
20+
"""
21+
22+
flag = 0
23+
for ele in firstWord:
24+
if ele in secondWord:
25+
flag = 1
26+
continue
27+
else:
28+
flag = 0
29+
break
30+
return True if (flag) else False
31+
32+
33+
if __name__ == "__main__":
34+
firstWord = input("Enter the first word: ").strip()
35+
secondWord = input("Enter the second word: ").strip()
36+
if anagram(firstWord, secondWord):
37+
print(f"{firstWord} and {secondWord} are Anagrams.")
38+
else:
39+
print(f"{firstWord} and {secondWord} are not Anagrams.")

0 commit comments

Comments
 (0)