subject

#write a function called rabbit_hole. rabbit_hole should have#two parameters: a dictionary and a string. the string may be#a key to the dictionary. the value associated with that key,#in turn, may be another key to the dictionary.##keep looking up the keys until you reach a key that has no#associated value. then, return that key.##for example, imagine if you had the following dictionary.#this one is sorted to make this example easier to follow: ## d = {"bat": "pig", "pig": "cat", "cat": "dog", "dog": "ant",# "cow": "bee", "bee": "elk", "elk": "fly", "ewe": "cod",# "cod": "hen", "hog": "fox", "fox": "jay", "jay": "doe",# "rat": "ram", "ram": "rat"}##if we called rabbit_hole(d, "bat"), then our code ## - look up "bat", and find "pig"# - look up "pig", and find "cat"# - look up "cat", and find "dog"# - look up "dog", and find "ant"# - look up "ant", and find no associated value, and so it would# return "ant".##other possible results are: ## rabbit_hole(d, "bat") -> "fly"# rabbit_hole(d, "ewe") -> "hen"# rabbit_hole(d, "jay") -> "doe"# rabbit_hole(d, "yak") -> "yak"##notice that if the initial string passed in is not a key in#the dictionary, that string should be returned as the result as#well.##note, however, that it is possible to get into a loop. in the#dictionary above, rabbit_hole(d, "rat") would infinitely go#around between "rat" and "ram". you should prevent this: if a#key is ever accessed more than once (meaning a loop has been#reached), return the boolean false.##hint: if you try to access a value from a dictionary that does#not exist, a keyerror will be raised

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:30, lilpeepxliltracy
This technology is used to produce high-quality documents that look good on the computer screen and in print.
Answers: 1
image
Computers and Technology, 22.06.2019 18:00, Geo777
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
image
Computers and Technology, 23.06.2019 03:00, Julianhooks
State 7 common key's for every keyboard
Answers: 1
image
Computers and Technology, 25.06.2019 00:30, alinton06
What is a typeface? a. a collection of similar text b. a collection of similar fonts c. a collection of similar designs d. a collection of similar colors e. a collection of similar images
Answers: 1
You know the right answer?
#write a function called rabbit_hole. rabbit_hole should have#two parameters: a dictionary and a st...

Questions in other subjects: