I want to see if there is a more efficient way of writing over a million rows of data to a text file. I'm currently calling write
over a million times which I believe is costly. I'm looping through each item in a huge s3 bucket to write each object id + some metadata to a text file one by one. Should I be looping through the bucket first, storing in a list or dict and then writing that entire list/dict at once? Or do it one by one?
list_of_million = [1,2,3,4,5......]
with open("Output.txt", "wb") as text_file:
for data in list_of_milion:
text_file.write(data)