[Tutor] Help please
Peter Otten
__peter__ at web.de
Thu Oct 17 15:37:49 CEST 2013
Alan Gauld wrote:
[Ruben Pinedo]
> def process_file(filename):
> hist = dict()
> fp = open(filename)
> for line in fp:
> process_line(line, hist)
> return hist
>
> def process_line(line, hist):
> line = line.replace('-', ' ')
>
> for word in line.split():
> word = word.strip(string.punctuation + string.whitespace)
> word = word.lower()
>
> hist[word] = hist.get(word, 0) + 1
[Alan Gauld]
> If so you need to fix the bugs in process_line() and
> process_file(). I don;t know if these are deliberate bugs
> or somebody is just sloppy. But neither work as expected
> right now. (Hint: Consider the return values of each)
I fail to see the bug.
process_line() mutates its `hist` argument, so there's no need to return
something. Or did you mean something else that escapes me?
More information about the Tutor
mailing list