import hashlib


def hash_data(data_in, encode=True):
    """
    Given a (list of) string or bystring data_in  generate the MD5 hash
    and return its hexadecimal value

    args:
        data_in:: str, list[str]
            a string or list of strings representing the data to be hashed
        encode:: Boolean
            whether to encode the data or not - if it has already been converted
            to bytes

    returns:
        result:: str
            a (list of) MD5 hash of data_in
    """

    if not isinstance(data_in, list):
        data_list = [data_in]
    else:
        data_list = data_in

    if encode:
        func = lambda x: hashlib.md5(x.encode()).hexdigest()
    else:
        func = lambda x: hashlib.md5(x).hexdigest()

    result = list(map(func, data_list))

    return result if isinstance(data_in, list) else result[0]