+ 23
[ASSIGNMENT] String Anagram.
Write a program to check if two given String is Anagram of each other. Your program should print true if two Strings are Anagram, false otherwise. A string is said to be an anagram if it contains same characters and same length but in different order. For example: If the input strings are 'listen' and 'silent'. The output should be True. P.S. I submit the challenges in lesson factory so that they can be made assignments.But till they get approved i post them here so as to help everyone practice.
34 Answers
+ 26
I guess I was too insensitive 😂🤣🤣🤣🤣🤣🤣
updated :-
print(sorted(input().lower()) == sorted(input().lower()))
+ 19
#My try in Python (1Liner) :-
print(sorted(input())==sorted(input()))
edit :- check the updated version...
+ 11
https://code.sololearn.com/czMBi9u62O6t/?ref=app
+ 8
@mitali jadhavrao
Thank you 😉
+ 7
# python
def are_anagrams(s, ss):
a = sorted(s.lower())
b = sorted(ss.lower())
return a == b
# EDIT: lists not needed, indeed ☺️
+ 5
Hechmi Barhouma Thank you for pointing it out.👍👍
Also ur solution is great.
Thanks for participating in this challenge. 😊
+ 5
Pedro Demingos Good you have also taken care of the case.👍
+ 4
Hechmi Barhouma It would check only the first matching character n return True.It wont go to next character because of return statement.
Make few changes.
Nice try👍
+ 4
Hechmi Barhouma:
In addition to the problem pointed by mitali jadhavrao, you could have false positives with your logical mistake...
Testing if each letter of a word is present in the other one is not enough to proove that they're anagram ^^ You need also test that other one don't have letter not used in first word, and that each word use same count of each letter ;P
Python short solution:
def is_anagram(a,b):
return ''.join(sorted(list(a))) == ''.join(sorted(list(b)))
print(is_anagram('silent','listen')) # True
+ 4
🌛DT🌜 Great logic.👍👍
Thanks for participating.
+ 4
Keegorp Good try.👍👍
The code is awesome.
Thanks for taking part😊
+ 4
hinanawi Both the codes are great.👍
+ 4
LukArToDo Good one 👍
+ 3
+ 3
Russ Well i dont see any reason why someone has downvoted.
Just a suggestion ...see for cases.
Nice try👍.
+ 2
My answer:
https://code.sololearn.com/cZhap0UB8JuW/#c