Semi-Newbie needs a little help
MRAB
python at mrabarnett.plus.com
Mon Jul 6 19:41:53 EDT 2009
Nile wrote:
[snip]
> I initialized the dictionary earlier in the program like this -
>
> hashtable = {}
>
> I changed the "dict" to hashtable but I still get the same result
> I will try to learn about the defaultdict but I'm just trying to keep
> it as simple as I can for now
>
> Revised code
>
> for x in range(len(file_list)):
> d = open(file_list[x] , "r")
> data = d.readlines()
What's the point of the following line?
> k = 0
> k = above_or_below(data)
> print "here is the value that was returned ",k
> hashtable[k] = hashtable.get(k,0) + 1
>
>
> hashtable_list = hashtable.values()
> print "here is a list of the dictionary values ", hashtable_list
> print "the length of the dictionary is ", len(hashtable)
>
> Output
> # The first 3 lines are printed from the function
> # right before the return statement. This output
> # snippet shows the last two stocks. The function
> # SAYS it is returning the correct value but only
> # the last date seems to make it to the hashtable
> Function will return k which = 11/11/2008
> Function will return k which = 11/12/2008
> Function will return k which = 11/14/2008
>
> # this line is printed from the code above
> # I don't understand why all three dates don't
> # seem to make it to the main program. Only
> # the last date seems to be recognized
> here is the value that was returned 11/14/2008
>
> Function will return k which = 11/11/2008
> Function will return k which = 11/12/2008
> Function will return k which = 11/14/2008
> here is the value that was returned 11/14/2008
> here is a list of the dictionary values [5]
> the length of the dictionary is 1
>> Exit code: 0
I think there's a bug in 'above_or_below' which you haven't noticed.
More information about the Python-list
mailing list