-6

Team,

any hint what am i missing? am checking if two strings are anagram and get no result

# sol1 
def anagram_from_identical_chars(s1,s2):
    s1 = s1.replace(' ','').lower()
    s2 = s2.replace(' ','').lower()
    return sorted(s1) == sorted(s2)
anagram_from_identical_chars('add','dad')

output: empty

expected

True
AhmFM
  • 1,552
  • 3
  • 23
  • 53
  • 9
    Maybe you need to print your returned value? – progmatico Nov 16 '20 at 22:40
  • Does this answer your question? [How is returning the output of a function different from printing it?](https://stackoverflow.com/questions/750136/how-is-returning-the-output-of-a-function-different-from-printing-it) – L.Grozinger Nov 16 '20 at 22:43
  • why is there a -5 to my post? am new to python sometimes other posts don't help everyone. – AhmFM Nov 16 '20 at 22:54
  • Related: [*"Checking strings against each other (Anagrams)"*](https://stackoverflow.com/questions/14990725) – bad_coder Nov 17 '20 at 14:52

1 Answers1

3

Adding a print will be enough:

def anagram_from_identical_chars(s1,s2):
    s1 = s1.replace(' ','').lower()
    s2 = s2.replace(' ','').lower()
    return sorted(s1) == sorted(s2)

print(anagram_from_identical_chars('add','dad'))
lorenzozane
  • 1,214
  • 1
  • 5
  • 15
  • Your syntax is wrong you need to leave a line between the `return` statement and the `print` statement – GAP2002 Nov 16 '20 at 22:50
  • @GAP2002 are you serious? – lorenzozane Nov 16 '20 at 22:51
  • yes run this in your terminal you will get a syntax error – GAP2002 Nov 16 '20 at 22:52
  • 1
    works. thanks for print prointer. space had nothing to do though. it worked without having to insert space. – AhmFM Nov 16 '20 at 22:53
  • @GAP2002 absolutely not. Your statement has not the slightest foundation, I'm sorry – lorenzozane Nov 16 '20 at 22:54
  • `File "", line 5` `print(anagram_from_identical_chars(s1,s2))` ` ^` `SyntaxError: invalid syntax` For me – GAP2002 Nov 16 '20 at 22:55
  • @GAP2002 Could be a problem with your compiler, certainly not the code. Try copying and pasting on https://repl.it/languages/python3 and see. Where are you trying to run it? – lorenzozane Nov 16 '20 at 22:57
  • I'm running it in Python 3.9 from my terminal – GAP2002 Nov 16 '20 at 23:00
  • 1
    @LorenzoZane He's pasting it into his command-line interpreter. Your code is correct, it's just a quirk of how it determines when code-blocks are terminated. – Hampus Larsson Nov 16 '20 at 23:00
  • @LorenzoZane as Hampus Larsson said it is correct and it is a quirk, however, I am not wrong. PEP8 style guide [here](https://www.python.org/dev/peps/pep-0008/#blank-lines) explains more, but you should leave a blank line to make the code more readable although it does "work" without doing so. – GAP2002 Nov 17 '20 at 00:30
  • @GAP2002 Style guide != Syntax of a language. Your statements about his code was factually incorrect. – Hampus Larsson Nov 17 '20 at 08:05