Jul-14-2020, 07:53 PM
You are using a dictionaries. There is no reason to loop through the keys to find matches. Instead of doing this:
for element in inner_selist: for key,value in meta_data.items(): if key == element: in_se = key if "Expression" in value: inner_selist1 = re.findall(r"Expression\('(.*?)'\)",value.strip()) if inner_selist1: inner.append({"Level1_": inner_selist1})Do this
for element in inner_selist: if value := meta_data.get(element): in_se = element if "Expression" in value: if inner_selist1 := re.findall(r"Expression\('(.*?)'\)",value.strip()): inner.append({"Level1_": inner_selist1})This does appear to be a good problem for a recursive solution, especially if you don't know the maximum depth of NestedVariable.depth. A detailed description of what this code does, what the input is and what you want for output is a good first step at defining what the recursive function will do. Once you have a description of what the recursive function does, writing the code is simple.