Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with code only after #your code here ( fixing the code I wrote there will be priority, if none of my code work,
Please help with code only after #your code here fixing the code I wrote there will be priority, if none of my code work, please kindly provide your code Code will be tested with the great gatsby and war and peace txt I would also like to know how to fix the error TypeError: 'tuple' object is not callable Thanks in advance.
Problem : Using a Bloom Filter to Count Common Words.
In this problem, we will implement a Bloom filter to count how many elements of longe rwordswp 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.def initself nbits, nhash: self.m nbits ## get k randdom hash functions# Function to insert a word in a Bloom filter. # your code here index hashfnword# Check if a word belongs to the Bloom Filter # your code here index hashfnword return True
In :
##o 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 :bf BloomFilter
for word in longerwordsgg:for word in longerwordsgg:commonwordcount
for word in longerwordswp: commonwordcount commonwordcount
printfNumber of common words of length equals : commonwordcount
assert commonwordcount exactcommonwc
printAll Tests Passed: points'
TypeError Traceback most recent call last
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started