I'm trying to transform each word from a txt file so that the carriage return is removed, and then have the words printed out. However, there's an extra newline at the end when I run the code. I checked for any extra spaces in the code, but I'm not sure how to remove it.
This is what I typed in:
f = open("/home/pride_and_prejudice.txt").read()
for word in f.split("\n"):
word_new = word.rstrip("\n")
print(word_new)
This should give me:
It
is
a
truth
universally
acknowledged
that
a
single
man
in
possession
of
a
good
fortune
must
be
in
want
of
a
wife
However
little
known
the
feelings
or
views
of
such
a
man
may
be
on
his
first
entering
a
neighbourhood
this
truth
is
so
well
fixed
in
the
minds
of
the
surrounding
families
that
he
is
considered
as
the
rightful
property
of
some
one
or
other
of
their
daughters