Question: Please help to fix my error and only change the code under #your code here. I've also included a screenshot of the error shown. Traceback
Please help to fix my error and only change the code under #your code here.
I've also included a screenshot of the error shown.
Traceback most recent call last
Problem : Using a Bloom Filter to Count Common Words.
In this problem, we will implement a Bloom filter to count how many elements of longerwordswp the words of length or more in War and Peace
appear in the GreatGatsby novel. To do so we will do the following:
Instantiate a Bloom filter with number of bits and number of hash functions
Insert all words from greatgatsby into the filter.
For each word from war and peace, check membership in the Bloom filter and count the number of yes answers.import hashlib
class BloomFilter: self.bits Falsenbits # Initialize all bits to fals self.k nhash self.hashfunreps getrandomhashfunction for i in rangeselfk seed random.randint self.m # Function to insert a word in a Bloom filter. # your code here index hashfunword# Check if a word belongs to the Bloom Filter # your code here index hashfun word return FalseIn :
#do the exact countthis operation finishes very quickly.
allwordsgg setlongerwordsgg
exactcommonwc
for word in longerwordswp: exactcommonwc exactcommonwc
printfExact common word count exactcommonwc
Exact common word count
In : # Try to use the same using a bloom filter.for word in longerwordsgg:for word in longerwordsgg:commonwordcount if bfmemberword:printfNumber of common words of length equals : commonwordcountprintAll Tests Passed: points'
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
