WEBVTT 00:00:00.008 --> 00:00:04.570 Here's the answer; we can define hashtable_get_bucket, and 00:00:04.570 --> 00:00:07.280 it takes two inputs, the hash table, we'll 00:00:07.280 --> 00:00:10.110 call that htable, and the key, which is 00:00:10.110 --> 00:00:12.960 the word we're looking for. And to find the 00:00:12.960 --> 00:00:16.290 bucket, well, we're going to use hash_string. We're going to 00:00:16.290 --> 00:00:19.600 pass in the same word, the keyword, that's the 00:00:19.600 --> 00:00:22.180 input key. The number of buckets is the 00:00:22.180 --> 00:00:25.650 length of this table, so we're going to call hash_string, 00:00:25.650 --> 00:00:29.500 passing in the key. And as the second input, we need 00:00:29.500 --> 00:00:33.690 the length of the table, that's the number of buckets. So 00:00:33.690 --> 00:00:36.710 that will get us a number which is the index of 00:00:36.710 --> 00:00:38.880 the bucket we want. To get that bucket, we need to 00:00:38.880 --> 00:00:42.590 use that as the index to select that element from htable, 00:00:42.590 --> 00:00:44.840 and then we want to return the results. So that's all 00:00:44.840 --> 00:00:47.930 we need to find the bucket. Let's look at that in 00:00:47.930 --> 00:00:50.900 the Python interpreter. So here's the code we have so far. 00:00:50.900 --> 00:00:53.590 We have the hash string procedure we defined that maps 00:00:53.590 --> 00:00:57.410 the key word and a number of buckets to the position 00:00:57.410 --> 00:01:00.130 where that should occur in the hash table. We have 00:01:00.130 --> 00:01:03.650 the make_hashtable procedure that creates an empty table with that number 00:01:03.650 --> 00:01:07.100 of buckets. And now we have the hashtable_get_bucket procedure that 00:01:07.100 --> 00:01:09.300 takes a hash table and a key. And give this the 00:01:09.300 --> 00:01:12.120 element of the hash table which is where that key would 00:01:12.120 --> 00:01:15.310 belong using that hash string function to find the right position.