def join_list_for_MATLAB(join_str:str, ls:list,
                         min_len:int =75, 
                         add_semicolon:bool =False, 
                         comment:bool=False, 
                         preface:str =''): 
    """Function to take a list and join it together with a delimiter as str.join(ls) does 
    except, you actually insert a MATLAB style line break where the lines start to get 
    long. Doesn't append delimiter to beginning or end.
    
    Inputs: 
        join_str = string delimiter you want to use to join the list: ',', '+'  ... 
        ls   = list of items you want to join with join_str. 
        min_len = int that is the minimum line lenth they must be before inserting a line break. 
        add_semicolon = boolean of wehther to add a semi colon at then end or not. 
        comment = boolean of whether the entire list should be commented our or not. 
        
    Outputs- Single string that has all items in list joined with delimiters and 
            MATLAB style line breaks where lines are long. 
            
    Example Usage:
        ls=['a'*np.random.randint(5,65) for i in range(0,100)] # random list. 
        join_str=' + ' # Delimiter you want to join this list. 
        out = join_list_for_MATLAB(join_str, ls)
        print(out)       

    Author: Jessica D. Haskins (jhaskins@alum.mit.edu) GitHub: @jdhask 
    
    1.14.2022   JDH created.                                      
    """
    ad=';' if add_semicolon is True  else '' 
    
    ln_ls=[]; lines=[]
    for i, item in enumerate(ls): 
        if type(item) != str: item=str(item) # Join only takes string lists. 
        if len(item) > 0: # Don't join things that are blanks. 
            ln_ls.append(item)
            ln= join_str.join(ln_ls) 
            if len(ln) > min_len: 
                if comment is True and i != 0: ln='% '+ln
                lines.append(ln) # Keep all these joined strings. They will be on 1 line. 
                ln_ls=[]; # reset list holding items to put on a single line.  
    
    if len(lines)==0: # Stuff wasn't long enough! So write one line with it on it. 
        out=preface+join_str.join(ls)+ad
    else:
        # Join each line together with the MATLAB line break and new line character 
        to_join= join_str+'...\n    ' 
        out=to_join.join(lines)+ad
    
    return out