Question: Complete the below function which takes a dictionary d and a key k as arguments and returns a value based on the following rules: 1.

Complete the below function which takes a dictionary d and a key k as arguments and returns a value based on the following rules:

1. If k is not a key of d, then return None. 2. Otherwise, let v be the value of k in d 3. If v exists also as a KEY in d, then set k = v and go to Step 2 4. Otherwise, return v

For example, given d={1:3, 3:2, 2:4} and k = 1, your function must return 4. This is because d[1] is 3, and d[3] is 2, and d[2] is 4, and 4 is not a key in d. """

def dictChain(d, k): return # Remove this line if you want to answer this question (ptyhon)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!