I got stuck while learning on-line Python 3 (Coursera. Love them).
I have a .txt
file with several lines. each line has several words in it. I need to split the files to line, I'm already using:
for line in fh:
line = line.rstrip()
line.split()
Now I need to sort the words from the entire file (from all the lines) Alphabetically, but I get are strings in the list (that I already created named lst
). So I get the entire strings sorted alphabetically but couldn't sort the words inside them sorted.
I see that it looks like the question already been asked, but it's a little bit different. Let's take this text for example :
"In the beginning of creation of the heavens and the earth
Now the earth was astonishingly empty and darkness was"
What I need is to sort the entire list of words alphabetically (after trimming same words), so the result should be ['In', 'Now', 'and', 'astonishingly', 'beginning']
and so on.
I really tried to find in myself and I'm taking this course seriously. I need some help here.
Thank you in advance,