Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Recursive Nested Data Search

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Recursive Nested Data Search. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

How would you write a function to find a value inside a nested dictionary using recursion?

Implement find_value(data, target) to return True if target appears as a value at any depth, including the top level, and False otherwise. Dictionary keys are not searched. Assume the input contains dictionaries and non-dictionary values only, with no cyclic references.

Constraints

  • data is a dictionary
  • Nested values are dictionaries or non-dictionary values
  • Dictionary keys are not searched
  • The structure contains no cyclic references

Function Signature

def find_value(data, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output