I am trying to write the contents of 2d list in a specific pattern that needs to be read by another file too. After writing the code, The text file mess up. Help me out from this issue.Thanks
I have tried using a loop to write the contents to text file but I failed.
list_final=[['Harry Potter', 'JK Rowling', '55', '2'], ['Start With Why', 'Simon Sinek', '42', '1.5'], ['P With Python', 'John Smith', '40', '1.5']]
file_contain_db_write = open("books.txt", "w")
for each in list_final:
file_contain_db_write.write(str(", ".join(str(each))))
file_contain_db_write.write("\n")
file_contain_db_write.close()
My expected result:
My code output: