You can add a trailing newline character to each element in the list before joining them using '\n'.join(my_list). Here's an example:
mylist = ["line 1", "line 2", "line 3"] mylistwithnewlines = [line + "\n" for line in mylist] text = ''.join(mylistwithnewlines)
This will add a newline character at the end of each line (except for the last one) and then join them using the '\n' separator.
Asked: 2023-05-10 20:47:04 +0000
Seen: 11 times
Last updated: May 10 '23