DisjointSet class in Python
I'll edit this once it's posted what the code is supposed to do.

The code is extremely cryptic. There are no comments; the variable &amp; membervariable names are all abbreviations. Someone else looking at this code will have no idea what is supposed to be happening. At the very least there should be docstrings at the start of each function/method that describe what the function is used for and the purposes of each variable.

The only possible performance improvement I see is to combine the __par, __csz, and __root members since they all have the same keys. That way the same element doesn't need to be hashed multiple times. The data structure, instead of being split between three dictionaries each of which being a member variable/field, would just have one dictionary with appropriate keys and the values being a list of [parent, csz, root].

def __init__(self, s=set()):
  self.__data = {x: [x, 1, x] for x in s}

def add(self, x):
  if x not in self.__data:
    self.__data[x] = [x, 1, x]


If you need one of the members you just refer to self.__data[x][0] or whatever.