Answered step by step
Verified Expert Solution
Question
1 Approved Answer
################################################ #### class Dictionary to complete step by step ################################################ import urllib.request import random class Dilctionary: def _init__(self,link): # constructor (provided) dict=urllib.request.urlopen(link). read(). decode( utf-8)
\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\#\#\# class Dictionary to complete step by step \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# import urllib.request import random class Dilctionary: def _init__(self,link): \# constructor (provided) dict=urllib.request.urlopen(link). read(). decode( "utf-8") \# load full dictionary file as string self.__words=dict.split(" ) \# create list of words (private) self._steps=0 \# private attribute self.__index=0 \# private attribute random, seed(7) \# initialize the seed for random reproducibility \#def get_steps \#def get_index \#def size "" " return the length of the dictionary "" " \#def lsearch "" "linear search, must return True or False (if input word is found) Remark: make sure you exit as soon as you found the word. Also you would need to reinitialize and update the index and steps private attribute here as well If a word is not found, set the index at 1 \#def bsearch "n"binary search, must return True or False (if input word is found) Remark: you can simply compare two words (lexicographically/alphabetically) using the operator ,== Also you would need to reinitialize and update the index and steps private attribute here as well If a word is not found, set the index at 1 \#def random "" "return a word a random in the dictionary you need to use the function randint from the random module
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