Animals

Report a typo

The file animals.txt has a list of animals, each written on a new line. For example:

rabbit
cat
turtle

Create a new file, animals_new.txt, where those animals are written on a single line and separated by a whitespace.

Don't forget to close all files!

Tip: The fact that animals in the first file are written each on a new line means that each string in the file, except for the last one, ends with '\n'. To get rid of \n, you can use either str.rstrip() or str.replace() methods.

Write a program in Python 3
# read animals.txt
# and write animals_new.txt
___

Create a free account to access the full topic