Hi again
I’m working with the text file and I need suggestions about 2,4,5? and mybe about 1 and 3 also.
For example I have this text.
“I love the python programming
How love the python programming?
We love the python programming
Do you like python for kids?
I like Hello World Computer Programming for Kids and Other Beginners.”
1.Read a text file and extract all word?
2.count the number of different words?
3. Count for each word the number of occurrences?
4. Display the list of words and their occurrences sorted by the alphabetical order?
5. Same list but sorted mainly by the number of occurrences, and if two words have the same number
of occurrences, sorted by the alphabetical order?
1)
f = open ("data.txt")
lines = f.readlines()
for line in lines:
print line
3)
count = {}
for word in open('data.txt').read().split():
if word in count:
count[word] += 1
else:
count[word] = 1
for word, times in count.items():
print "The", word, "was found", times, "times"
outPut
================================ RESTART ================================
The and was found 1 times
The do was found 1 times
The we was found 1 times
The Kids was found 1 times
The love was found 3 times