0

I am trying to compute the hash function for a string and I am receiving a syntax error about how to convert a character at position x to an integer value. Anyone know how to correctly do this?

def hashFunction(inputString, r, m):

    for x in range(0,len(inputString)-1):
        hashValue = (hashValue*r+(ord)inputString[x])% m 
    return hashValue

1 Answer 1

1

I see two issues, first of all, you're not calling ord on an argument. You probably want this:

    hashValue = (hashValue*r+ord(inputString[x]))% m 

Notice how I wrapped the argument in parentheses instead of around the function name.

The second thing is that you're using the value of hashValue when it hasn't been assigned to yet. This will give you an error when you call the function.

Sign up to request clarification or add additional context in comments.

Comments

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.