Sorry, one more question!

Dear Mentors:

In Exercise 10 of the assignment for Week 4, I got stuck again.

In the for-loop to store the index and vectors in ‘vecs,’
I encountered the error below.

TypeError: object of type 'int' has no len()

The problematic part of my code is:
id_table[h] = i

I still don’t understand what dimension this list should have.
I actually initialized both the hash table and the id table as follows:

hash_table = {i:[] for i in range(num_buckets)}
id_table = {i:[] for i in range(num_buckets)}

However, due to the enumeration of ‘vecs’ in the for-loop,
The dimensions of hash_table and id_table will differ from each other.

How can I solve this problem?
Please give me some advice.

Best wishes,

Hi, I think when you’re setting id_table[h] = i you’re setting a list as an int instead of adding the item to the list.

Thank you for your quick response, davidguo94!

In fact, I was able to solve the problem by myself.
As you mentioned, I just overwrote the value of the dict, id_table,
not appending the corresponding index of each vector into the dict.

I modified my code as follows:

Sorry for bothering you. But thanks.