I wrote a function in Python to sort my data into a dictionary syntax, but because I'm using while, there is a comma that I would like to remove to avoid having an invalid syntax.
For example with the following code:
file = open("test.txt","w", encoding="utf-8")
number = 0
while number < 5:
file.write("some text" + ", ")
number += 1
This will create test.txt with the following text inside:
some text, some text, some text, some text, some text,
I would like to remove the last ", " added by at the end to look like:
some text, some text, some text, some text, some text
Any idea?
.joinmethods if it is a list or something) and write one sentence at a time. essentially, dont use the inner while loop, but instead construct and write a sentence at a time.