Skip to content
Advertisement

My python function is returning None, even if after declaring return statement. I’m unable to understand where I am legging. Recursion is mandatory

JavaScript

”’ jsondict = { “condition”: “AND”, “rules”: [ { “id”: “price”, “field”: “price”, “type”: “double”, “input”: “number”, “operator”: “less”, “value”: 10.25 }, { “condition”: “OR”, “rules”: [ { “id”: “category”, “field”: “category”, “type”: “integer”, “input”: “select”, “operator”: “equal”, “value”: 2 }, { “id”: “category”, “field”: “category”, “type”: “integer”, “input”: “select”, “operator”: “equal”, “value”: 1 } ] } ] }

JavaScript

”’

Advertisement

Answer

  1. In the 2nd step of recursion, you apply your rules method to this kind of dicts:

{ “id”: “category”, “field”: “category”, “type”: “integer”,
“input”: “select”, “operator”: “equal”, “value”: 2 }

It does not work because there is no “rules” key.

  1. Moreover, returning the function causes a break of for loop. Call the method without the “return” keyword.

Try something like this:

JavaScript
Advertisement