Z21500

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z21500"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z21499",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z610",
            "Z16K2": "def Z21499(Z21499K1):\n    #\n    # v2.0, \"safe\" Numerical expression evaluation as python \"eval\" replacement\n    # Multiple nested expressions using parenthesis, allowed\n    # Evaluate simple numerical expresssion, ie NO functions allowed\n    #\n    from re import search,sub,escape\n    if search(r'[a-zA-Z]',Z21499K1):\n        raise ValueError('Not a valid numerical expression')\n    #\n    # simple_eval: Evaluate simple numerical expression\n    #\n    def simple_eval(expression: str):\n        expression_:str =sub(r\"\\s\",\"\",expression)\n        operator: list[dict] = [{\n            '**': lambda x, y: x ** y,\n    \t},{\n            '~' : lambda    y:     ~y,\n    \t},{\n            '*' : lambda x, y: x *  y,\n\t    \t'/' : lambda x, y: x /  y,\n\t    \t'//': lambda x, y: x // y,\n\t    \t'%' : lambda x, y: x %  y,\n\t    \t'+' : lambda x, y: x +  y,\n\t    \t'-' : lambda x, y: x -  y,\n\t    },{\n\t    \t'\u003C\u003C': lambda x, y: x \u003C\u003C y,\n\t    \t'\u003E\u003E': lambda x, y: x \u003E\u003E y,\n\t    \t'\u0026' : lambda x, y: x \u0026  y,\n\t    \t'^' : lambda x, y: x ^  y,\n\t    \t'|' : lambda x, y: x |  y,\n\t    }]\n        #\n        i: int =0\n        for _ in operator[i].keys():\n            pattern_=r\"([0-9\\.]+)\"+escape(_)+r\"([-|+|~]*[0-9\\.]+)\"\n            match_=search(pattern_,expression_)\n            while match_ is not None:\n                if    float(match_.group(1)).as_integer_ratio()[1]==1 \\\n                  and float(match_.group(2)).as_integer_ratio()[1]==1:\n                    arithmetic_ =operator[i][_](int(match_.group(1)),int(match_.group(2)))\n                else:\n                    arithmetic_ =operator[i][_](float(match_.group(1)),float(match_.group(2)))\n                if arithmetic_.as_integer_ratio()[1]==1:\n                    expression_=expression_.replace(match_.group(0),str(int(arithmetic_)),1)\n                else:\n                    expression_=expression_.replace(match_.group(0),str(arithmetic_),1)\n                match_=search(pattern_,expression_)\n        #\n        i =1\n        for _ in operator[i].keys():\n            pattern_ =escape(_)+r\"([-|+|~]*[0-9\\.]+)\"\n            if search(r\"[0-9]\"+pattern_,expression_) is None:\n                match_ =search(pattern_,expression_)\n            while match_ is not None:\n                arithmetic_ =operator[i][_](int(match_.group(1)))\n                expression_ =expression_.replace(match_.group(0),str(arithmetic_),1)\n                match_ =search(pattern_,expression_)\n        #\n        i =2\n        for _ in operator[i].keys():\n            pattern_ =r\"([-|+|~]{0,1}?[0-9\\.]+)\"+escape(_)+r\"([-|+|~]*[0-9\\.]+)\"\n            if search(r\"[0-9]\"+pattern_,expression_) is None:\n                match_ =search(pattern_,expression_)\n            else:\n                match_=search(r\"(\"+pattern_[14:],expression_)\n            while match_ is not None:\n                if    float(match_.group(1)).as_integer_ratio()[1]==1 \\\n                  and float(match_.group(2)).as_integer_ratio()[1]==1:\n                    arithmetic_ =operator[i][_](int(match_.group(1)),int(match_.group(2)))\n                else:\n                    arithmetic_ =operator[i][_](float(match_.group(1)),float(match_.group(2)))\n                expression_ =expression_.replace(match_.group(0),str(arithmetic_),1)\n                match_ =search(pattern_,expression_)\n        #\n        i =3\n        for _ in operator[i].keys():\n            pattern_ =r\"([-|+|~]{0,1}?[0-9\\.]+)\"+escape(_)+r\"([-|+|~]*[0-9\\.]+)\"\n            if search(r\"[0-9]\"+pattern_,expression_) is None:\n                match_ =search(pattern_,expression_)\n            else:\n                match_=search(r\"(\"+pattern_[14:],expression_)\n            while match_ is not None:\n                arithmetic_ =operator[i][_](int(match_.group(1)),int(match_.group(2)))\n                expression_ =expression_.replace(match_.group(0),str(arithmetic_),1)\n                match_ =search(pattern_,expression_)\n        #\n        if float(expression_).as_integer_ratio()[1]==1:\n            return int(expression_)\n        else: return expression_\n    #\n    # Nested parenthesis evaluation, starting with the innermost and\n    # replacing it with its numerical evaluation with the output from\n    # \"simple_eval\" using its extracted subexpression \n    #\n    expression__:str =sub(r\"\\s\",\"\",Z21499K1)\n    pattern__:str =r\"\\(([^\\(\\)]*)\\)\"\n    match__ =search(pattern__,expression__)\n    while match__ is not None:\n        expression__ =expression__.replace(match__.group(0),str(simple_eval(match__.group(0)[1:-1]) ),1)\n        match__ =search(pattern__,expression__)\n    #\n    # Once, every nested parenthesis subexpression has been evaluated and\n    # replaced, we made the last final call to \"simple_eval\"\n    #\n    return simple_eval(expression__)\n#"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "DOnotCONNECTnumeric expression evaluation, python"
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1004",
                "Z11K2": "évaluation d'une expression numérique, en Python"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "python implementation, to evaluate from string numerical expressions.\nUsing Regular expressions, its tries mimic simple arithmetic operation with its precedence, while allowing nested groupping."
            },
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1004",
                "Z11K2": "en utilisant des expressions régulières, ses tentatives imitent une opération arithmétique simple avec sa priorité, tout en permettant un regroupement"
            }
        ]
    }
}