def myfn(m):
    return re.sub('\\s+', ' ', m.group().strip())
pat = re.compile('^\\w+\\s+=\\s\\(\\n.*?\\n\\)$', re.S | re.M)
mdls_output = pat.sub(myfn, mdls_output)
Efficiently replace multi-line list strings with single_line list string