Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive Function
#8
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.
Reply


Messages In This Thread
Recursive Function - by sridhar - Jul-14-2020, 03:40 PM
RE: Recursive Function - by DPaul - Jul-14-2020, 04:01 PM
RE: Recursive Function - by menator01 - Jul-14-2020, 04:07 PM
RE: Recursive Function - by ndc85430 - Jul-14-2020, 04:28 PM
RE: Recursive Function - by sridhar - Jul-14-2020, 04:07 PM
RE: Recursive Function - by DPaul - Jul-14-2020, 05:29 PM
RE: Recursive Function - by menator01 - Jul-14-2020, 06:40 PM
RE: Recursive Function - by deanhystad - Jul-14-2020, 07:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  with open context inside of a recursive function billykid999 1 658 May-23-2023, 02:37 AM
Last Post: deanhystad
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,464 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,728 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Execution of Another Recursive Function muzikman 5 3,162 Dec-04-2020, 08:13 PM
Last Post: snippsat
  Don't Understand Recursive Function muzikman 9 3,896 Dec-03-2020, 05:10 PM
Last Post: muzikman
  list call problem in generator function using iteration and recursive calls postta 1 2,030 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Recursive function returns None, when True is expected akar 0 3,482 Sep-07-2020, 07:58 PM
Last Post: akar
  factorial using recursive function spalisetty06 12 4,328 Aug-25-2020, 03:16 PM
Last Post: spalisetty06
  Nested Recursive Function not Returning Etotheitau 2 2,394 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Information "creeps up" in recursive function InigoMontoya 2 1,954 Sep-17-2019, 06:25 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020