[Tutor] Help please
Alan Gauld
alan.gauld at btinternet.com
Thu Oct 17 19:29:28 CEST 2013
On 17/10/13 14:37, Peter Otten wrote:
> Alan Gauld wrote:
>
> [Ruben Pinedo]
>
>> def process_file(filename):
>> hist = dict()
>> fp = open(filename)
>> for line in fp:
>> process_line(line, hist)
>> return hist
>> 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?
Oops, no, you are right, I forgot it's mutable. I don't
like that style but that is not a bug...
I was expecting to see a hist = process_line(...)
and a return hist in there...
My bad.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list