import re


def namelists(text):
    """Retrieves dictionary of namelists in text.

    Useful for isolating sub-namelists.

    >>> text = '''
    ... &namobs
    ...    ln_sst = .TRUE. ! Logical switch for SST observations
    ... /
    ... '''
    >>> namelists(text)
    {'namobs': '&namobs\\n   ln_sst = .TRUE. ! Logical switch for SST observations\\n/'}

    :param text: Input text to process

    :returns: A dictionary of id, text block key, value pairs

    """
    # Boundary case
    if text.startswith("&"):
        text = "\n" + text
    # Regular expression
    results = re.findall(r"\n(&(\w+).*?\n/)", text, re.DOTALL)
    data = {}
    for content, namid in results:
        data[namid] = content
    return data