def __init__(self, k, len_cntr):
<EOL>if len(len_cntr) < k:<EOL><INDENT>raise ValueError('<STR_LIT>' % (len(len_cntr), k))<EOL><DEDENT>self._k = k<EOL>self._len_cntr = len_cntr<EOL>self._lengths = sorted(self._len_cntr.keys())<EOL>self._splits = []<EOL>self._split2len_idx = {}<EOL>self._len2split_idx = {}<EOL>self._split_cntr = Counter()<EOL>lengths = []<EOL>unique_length = []<EOL>for length, count in list(self._len_cntr.items()):<EOL><INDENT>lengths.extend([length] * count)<EOL>unique_length.append(length)<EOL><DEDENT>lengths.sort()<EOL>unique_length.sort()<EOL>self._splits = [np.max(split) for split in np.array_split(lengths, self._k)]<EOL>"""<STR_LIT>"""<EOL>i = len(self._splits) - <NUM_LIT:1><EOL>while i > <NUM_LIT:0>:<EOL><INDENT>while self._splits[i - <NUM_LIT:1>] >= self._splits[i]:<EOL><INDENT>index = unique_length.index(self._splits[i - <NUM_LIT:1>])<EOL>if index == <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>self._splits[i - <NUM_LIT:1>] = unique_length[index - <NUM_LIT:1>]<EOL><DEDENT>i -= <NUM_LIT:1><EOL><DEDENT>unique_length.reverse()<EOL>i = <NUM_LIT:1><EOL>while i < len(self._splits) - <NUM_LIT:1>:<EOL><INDENT>while self._splits[i] <= self._splits[i - <NUM_LIT:1>]:<EOL><INDENT>index = unique_length.index(self._splits[i])<EOL>if index == <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>self._splits[i] = unique_length[index - <NUM_LIT:1>]<EOL><DEDENT>i += <NUM_LIT:1><EOL><DEDENT>split_idx = <NUM_LIT:0><EOL>split = self._splits[split_idx]<EOL>for len_idx, length in enumerate(self._lengths):<EOL><INDENT>count = self._len_cntr[length]<EOL>self._split_cntr[split] += count<EOL>if length == split:<EOL><INDENT>self._split2len_idx[split] = len_idx<EOL>split_idx += <NUM_LIT:1><EOL>if split_idx < len(self._splits):<EOL><INDENT>split = self._splits[split_idx]<EOL>self._split_cntr[split] = <NUM_LIT:0><EOL><DEDENT><DEDENT>elif length > split:<EOL><INDENT>raise IndexError()<EOL><DEDENT><DEDENT>old_splits = None<EOL>i = <NUM_LIT:0><EOL>while self._splits != old_splits:<EOL><INDENT>old_splits = list(self._splits)<EOL>self._recenter()<EOL>i += <NUM_LIT:1><EOL><DEDENT>self._reindex()<EOL>return<EOL>
Do clustering

        Parameters
        ----------
        k : int
            number of clusters
        len_cntr : Counter
            length counter