10

When I try to use this in my program, it says that there's an attribute error

'builtin_function_or_method' object has no attribute 'replace'

but I don't understand why.

def verify_anagrams(first, second):
    first=first.lower
    second=second.lower
    first=first.replace(' ','')
    second=second.replace(' ','')
    a='abcdefghijklmnopqrstuvwxyz'
    b=len(first)
    e=0
    for i in a:
        c=first.count(i)
        d=second.count(i)
        if c==d:
            e+=1
    return b==e

1 Answer 1

11

You need to call the str.lower method by placing () after it:

first=first.lower()
second=second.lower()

Otherwise, first and second will be assigned to the function object itself:

>>> first = "ABCDE"
>>> first = first.lower
>>> first
<built-in method lower of str object at 0x01C765A0>
>>>
>>> first = "ABCDE"
>>> first = first.lower()
>>> first
'abcde'
>>>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, I wasn't looking at the right place!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.