The problem of transferring js Code to python

problem description

I want to talk about a piece of code in d3.js converted to python, and then encountered a problem, that is, js can use functions like variables without passing parameter values. I don"t know how to implement the same function in my python.

here is the js code.
function defaultX$1(d) {
  return d[0];
}

function defaultY$1(d) {
  return d[1];
}

Python is also possible.
your problem may be that Python does not support the $symbol in identifiers .
your function name is marked with $. Remove $.

-sharp  __init__  addAll
class Quadtree:
    def __init__(self, a1, a2, a3, a4, a5, a6):
        pass
    def addAll(node):
        pass
def defaultX1(d):
    return d[0]
def defaultY1(d):
    return d[1]

def quadtree(nodes, x, y):
    tree = Quadtree(
        defaultX1 if x == None else x,
        defaultY1 if y == None else y,
        None, None, None, None
    )
    return tree if nodes == None else tree.addAll(nodes)
Menu