+ 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.

30th Mar 2018, 11:46 AM
Mitali
Mitali - avatar
34 Answers
+ 26
I guess I was too insensitive 😂🤣🤣🤣🤣🤣🤣 updated :- print(sorted(input().lower()) == sorted(input().lower()))
30th Mar 2018, 3:54 PM
🌛DT🌜
🌛DT🌜 - avatar
13th Apr 2018, 2:34 PM
MeanMachine
MeanMachine - avatar
+ 19
#My try in Python (1Liner) :- print(sorted(input())==sorted(input())) edit :- check the updated version...
30th Mar 2018, 1:43 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 11
https://code.sololearn.com/czMBi9u62O6t/?ref=app
31st Mar 2018, 10:04 AM
LukArToDo
LukArToDo - avatar
+ 8
@mitali jadhavrao Thank you 😉
31st Mar 2018, 10:57 AM
LukArToDo
LukArToDo - avatar
+ 7
# python def are_anagrams(s, ss): a = sorted(s.lower()) b = sorted(ss.lower()) return a == b # EDIT: lists not needed, indeed ☺️
30th Mar 2018, 2:58 PM
Pedro Demingos
Pedro Demingos - avatar
+ 5
Hechmi Barhouma Thank you for pointing it out.👍👍 Also ur solution is great. Thanks for participating in this challenge. 😊
30th Mar 2018, 2:26 PM
Mitali
Mitali - avatar
+ 5
Pedro Demingos Good you have also taken care of the case.👍
30th Mar 2018, 3:00 PM
Mitali
Mitali - avatar
+ 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👍
30th Mar 2018, 1:18 PM
Mitali
Mitali - avatar
+ 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
30th Mar 2018, 1:43 PM
visph
visph - avatar
+ 4
🌛DT🌜 Great logic.👍👍 Thanks for participating.
30th Mar 2018, 2:24 PM
Mitali
Mitali - avatar
+ 4
Keegorp Good try.👍👍 The code is awesome. Thanks for taking part😊
30th Mar 2018, 2:27 PM
Mitali
Mitali - avatar
+ 4
hinanawi Both the codes are great.👍
30th Mar 2018, 2:38 PM
Mitali
Mitali - avatar
+ 4
LukArToDo Good one 👍
31st Mar 2018, 10:24 AM
Mitali
Mitali - avatar
30th Mar 2018, 12:03 PM
Soufyane Bouchaala
Soufyane Bouchaala - avatar
+ 3
🌛DT🌜: Good point: I'm too much poluated by JS, and I've forgotten that sorted() doesn't require a list as argument, but an iterable such as a string, and that Python could compare list, without the need to join() them to compare two strings :P
30th Mar 2018, 1:55 PM
visph
visph - avatar
+ 3
Russ Well i dont see any reason why someone has downvoted. Just a suggestion ...see for cases. Nice try👍.
30th Mar 2018, 5:54 PM
Mitali
Mitali - avatar
30th Mar 2018, 6:34 PM
Baraa AB
Baraa AB - avatar