def compress(nodelist):
    """
    compress will return a hostlist string given a list of hostnames.

    :param: nodelist: The hostlist string.
    :return: The hostlist string.
    """
    if type(nodelist) == str:
        left_br = nodelist.replace('[', '')
        right_br = left_br.replace(']', '')
        nodelist = right_br.split(',')
    return '[%s]' % ','.join(map(str, nodelist))
