Aug-11-2022, 03:45 PM
If the extra commas can only be in the message column, then split on comma to get the first columns, then rsplit on comma to get the last columns.
# name, age, notes, zip_code table = '''Susan,27,works with HR on Zoom calls,02134 Roger,41,Gets coffee, bagels, and sodas for all the meetings,90210 ''' for row in table.splitlines(): name, age, rest = row.split(",", maxsplit=2) notes, zip_code = rest.rsplit(",", maxsplit = 1) print(f"Name: {name}. Notes: {notes}")
Output:Name: Susan. Notes: works with HR on Zoom calls
Name: Roger. Notes: Gets coffee, bagels, and sodas for all the meetings