← Quiz: How Hashing Works: all 13 questions
Quiz: How Hashing Works · Question 9 of 13
What does this print? (code)
What does this print?
def bucket(key, size):
return sum(ord(ch) for ch in key) % size
print(bucket("ab", 7), bucket("ba", 7), bucket("abc", 7))
- A.0 1 2
- B.6 0 0
- C.6 6 0
- D.1 1 6
Answer & explanation
Correct answer: 6 6 0
"ab" and "ba" have the same letter sum (195), so they collide in bucket 6; "abc" sums to 294, which is 0 mod 7.
Can you get the rest right without peeking?
Take the timed Quiz: How Hashing Works quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →