write python function,which takes one argument, which is a file name [as a string],and computes and prints out each word,followed by alist of lines(numbers),which contain that word.
eg the file is called("sample-text,txt") and then prints something like:
all:[20,30,40,48,50,59]
code:[34]
consider:[7]
found:[48]

Recommended Answers

All 2 Replies

And what have you done? Remember we are not just here to hand out free homework.

Show Effort

okay this is the way i tried:
"printing number of times each word appers in alist of lines"
f = open("C:\Documents and Settings\student\Desktop\test\sample-text.txt","r")
lines =f. readlines()
len(lines)
print lines
this one only reads number of lines and prints them out
I have failed to come up with the function which reads number of times each word appears in text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.