import re def strip_and_list(hosts): if hosts.strip() != '': sanitized = re.split("; |, | |\n", hosts) return sanitized # break