I need to be able to make python create a new text document that shows the list in a certain way and I am unsure of how to use formatting within the text creation area
def write_to_file(filename, character_list):
### Using a while loop to iterate over the list of lists (characters).
index = 0
while index < len(character_list):
with open("new_characters.txt", "w") as output:
output.write(str(character_list))
index = index + 1
The code above is what I have made to get the full list to show in the text document but it just puts it all in one line.
I am required to have it set up like this:
Wonder Woman
Diana Prince
h 5 5 0 0 90
Batman
Bruce Wayne
h 6 2 0 4 80
instead of:
[['Wonder Woman', 'Diana Prince', 'h', 5, 5, 0, 0, 90], ['Batman', 'Bruce Wayne', 'h', 6, 2, 0, 4, 80]
,
This is the output from the code posted above.
And the code must be in a loop!