code: def _k_modes_iter(
      X,
      centroids,
      cl_attr_freq,
      membship,
      dissim,
      random_state,
      sample_weight,
  ):
      """Single iteration of k-modes clustering algorithm"""
      moves = 0
      for ipoint, curpoint in enumerate(X):
          weight = (
              sample_weight[ipoint] if sample_weight is not None else 1
          )
          clust = np.argmin(
              dissim(centroids, curpoint, X=X, membship=membship)
          )
          if membship[clust, ipoint]:
              # Point is already in its right place.
              continue
  
          # Move point, and update old/new cluster frequencies and centroids.
          moves += 1
          old_clust = np.argwhere(membship[:, ipoint])[0][0]
  
          cl_attr_freq, membship, centroids = _move_point_cat(
              curpoint,
              ipoint,
              clust,
              old_clust,
              cl_attr_freq,
              membship,
              centroids,
              weight,
          )
  
          # In case of an empty cluster, reinitialize with a random point
          # from the largest cluster.
          if not membship[old_clust, :].any():
              from_clust = membship.sum(axis=1).argmax()
              choices = [
                  ii
                  for ii, ch in enumerate(membship[from_clust, :])
                  if ch
              ]
              rindx = random_state.choice(choices)
  
              cl_attr_freq, membship, centroids = _move_point_cat(
                  X[rindx],
                  rindx,
                  old_clust,
                  from_clust,
                  cl_attr_freq,
                  membship,
                  centroids,
                  weight,
              )
  
      return centroids, cl_attr_freq, membship, moves
  
imports: from collections import defaultdict
  import numpy
  from joblib import Parallel, delayed
  from scipy import sparse
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.utils import check_random_state
  from sklearn.utils.validation import check_array
  from .util import get_max_value_key, encode_features, get_unique_rows, decode_centroids, pandas_to_numpy
  from .util.dissim import matching_dissim, ng_dissim
  from .util.init_methods import init_cao, init_huang
label_desc: Use image node_id 4 for calling a global function with example usage: _k_modes_iter(X, centroids, cl_attr_freq, membship, dissim, random_state, sample_weight) and returns: centroids,  cl_attr_freq,  membship,  moves