I want to create a new CSV file with 3 items per row. My source file looks like (there are no new lines / line breaks):
File I/O neutral solution:
csv = """12123, 1324, 232324, 243443, 234, 2345
2334, 2445, 22355, 222234, 2345""" # replace this with the file you read from CSV
def sixPerLineToThreePerLine(s):
result = ""
for line in s.split("\n"):
sp = line.split(", ")
result = result + ", ".join(sp[:3]) + "\n" + ", ".join(sp[3:])
return result
print(sixPerLineToThreePerLine(csv)) # replace this with code to write to CSV