def marginal_counts(counts, meas_qubits):
    "\n    Compute the marginal counts for a subset of measured qubits.\n\n    Args:\n        counts (dict): the counts returned from a backend ({str: int}).\n        meas_qubits (list[int]): the qubits to return the marginal\n                                 counts distribution for.\n\n    Returns:\n        dict: A counts dict for the meas_qubits.abs\n        Example: if `counts = {'00': 10, '01': 5}`\n            `marginal_counts(counts, [0])` returns `{'0': 15, '1': 0}`.\n            `marginal_counts(counts, [0])` returns `{'0': 10, '1': 5}`.\n    "
    num_of_qubits = len(list(counts.keys())[0])
    qs = sorted(meas_qubits, reverse=True)
    meas_keys = count_keys(len(qs))
    rgx = [reduce((lambda x, y: ((key[qs.index(y)] if (y in qs) else '\\d') + x)), range(num_of_qubits), '') for key in meas_keys]
    meas_counts = []
    for m in rgx:
        c = 0
        for (key, val) in counts.items():
            if match(m, key):
                c += val
        meas_counts.append(c)
    return dict(zip(meas_keys, meas_counts))
Compute the marginal counts for a subset of measured qubits.

Args:
    counts (dict): the counts returned from a backend ({str: int}).
    meas_qubits (list[int]): the qubits to return the marginal
                             counts distribution for.

Returns:
    dict: A counts dict for the meas_qubits.abs
    Example: if `counts = {'00': 10, '01': 5}`
        `marginal_counts(counts, [0])` returns `{'0': 15, '1': 0}`.
        `marginal_counts(counts, [0])` returns `{'0': 10, '1': 5}`.
def marginal_counts(counts, meas_qubits):
    "\n    Compute the marginal counts for a subset of measured qubits.\n\n    Args:\n        counts (dict): the counts returned from a backend ({str: int}).\n        meas_qubits (list[int]): the qubits to return the marginal\n                                 counts distribution for.\n\n    Returns:\n        dict: A counts dict for the meas_qubits.abs\n        Example: if `counts = {'00': 10, '01': 5}`\n            `marginal_counts(counts, [0])` returns `{'0': 15, '1': 0}`.\n            `marginal_counts(counts, [0])` returns `{'0': 10, '1': 5}`.\n    "
    num_of_qubits = len(list(counts.keys())[0])
    qs = sorted(meas_qubits, reverse=True)
    meas_keys = count_keys(len(qs))
    rgx = [reduce((lambda x, y: ((key[qs.index(y)] if (y in qs) else '\\d') + x)), range(num_of_qubits), ) for key in meas_keys]
    meas_counts = []
    for m in rgx:
        c = 0
        for (key, val) in counts.items():
            if match(m, key):
                c += val
        meas_counts.append(c)
    return dict(zip(meas_keys, meas_counts))