Link to home
Start Free TrialLog in
Avatar of Dennie
Dennie

asked on

rewrite function in python

    
def temp(self, check_node, node):       
        while getattr(node, 'parent_node', None):
            node = node.parent_node
            if check_node == node:
                return True      

--------
if self.temp(check_node,node):
    do something

Open in new window



How can I rewrite def temp so I can directly use it in the if without having to create a seperate function?
Avatar of HonorGod
HonorGod
Flag of United States of America image

How deep can your nesting be?

Do you have an example initialized data structure?
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't have an answer, but why do you want to get rid of the function?

It seems to make your code more readable.

At least if you gave the function a proper name like found_node_in_parents
Thanks for the grade & points.

Good luck & have a great day