import re


def tokenize_per_cluster_args(args, nclusters):
    """
    Seperate per cluster arguments so that parsing becomes easy

    Params:
        args: Combined arguments
        nclusters(int): total number of clusters

    Returns:
        list of lists: Each cluster conf per list
            ex: [[cluster1_conf], [cluster2_conf]...]

    """
    per_cluster_argv = list()
    multi_cluster_argv = list()
    common_argv = list()
    cluster_ctx = False
    regexp = re.compile(r"--cluster[0-9]+")
    index = 0

    for i in range(1, nclusters + 1):
        while index < len(args):
            if args[index] == f"--cluster{i}":
                cluster_ctx = True
            elif regexp.search(args[index]):
                cluster_ctx = False
                break
            if cluster_ctx:
                per_cluster_argv.append(args[index])
            else:
                common_argv.append(args[index])
            index = index + 1
        multi_cluster_argv.append(per_cluster_argv)
        per_cluster_argv = []
    return multi_cluster_argv, common_argv