Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive Function
#1
Hi all ,
This is going to be crazy but I need to know how to do it. Please help me out folks.

The code which I'm using is not in a proper optimized way. Can anyone help me out in writing optimised code of it. (that is using recursive functions,etc..)

Here is my code:
NestedVariable is going to search from meta_data and it is type dict which I created already which act as input
         table1 = NestedVariable.text
            if "Expression" in table1:
                inner_selist = re.findall(r"Expression\('(.*?)'\)",table1.strip())
                if inner_selist:
                    inner.append({"Level0" : inner_selist})
                    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})
                                        for element in inner_selist1:
                                            for key1,value1 in meta_data.items():
                                                if key1 == element:
                                                    in_se1 = key1
                                                    if "Expression" in value1:
                                                        inner_selist2 = re.findall(r"Expression\('(.*?)'\)",value1.strip())
                                                        if inner_selist2:
                                                            inner.append({"Level2_" : inner_selist2})
                                                            for element in inner_selist2:
                                                                for key2,value2 in meta_data.items():
                                                                    if key2 == element:
                                                                        in_se2 = key2
                                                                        if "Expression" in value2:
                                                                            inner_selist3 = re.findall(r"Expression\('(.*?)'\)",value2.strip())
                                                                            if inner_selist3:
                                                                                inner.append({"Level3_" : inner_selist3})
                                                                                for element in inner_selist3:
                                                                                    for key3,value3 in meta_data.items():
                                                                                        if key3 == element:
                                                                                            in_se3 = key3
                                                                        else:
                                                                            level = 'level3'
                                                        
                                                    else:
                                                        level = 'level2'
                                    
                                else:
                                    level = 'level1'
                        
            else:
                level = 'level0'
Hope y'll understand my problem here.

Thanks in advance!
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,163 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,330 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,955 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