escribi�:
I am trying to find the amount of values there are pertaining to one key.What is a "multipart"? I know MIME multipart messages but they don't seem
For example:
- To find the average of the values pertaining to the key.
- Use the amount of values to calculate a histogram
to apply here...
From your other posts I think you're talking about a dictionary mapping
each key to a list of values.
So the values are contained inside a list. It doesn't matter *where* you
store that list, or *how* you get access to it. You have a list of values
- that's all.
Average values (asuming they're all numbers):
def avg(values):
# what to do with an empty list?
return float(sum(values))/len(values) # float() to avoid integer division
There are many libraries that provide histogram support, but using the
bisect module may be enough:
pyfrom random import randrange
pyfrom bisect import bisect
py>
pydata = [randrange(100)+randrange(100) for i in range(1000)]
pybins = range(0, 200, 20) # 0, 20, 40..180
pycounts = [0]*len(bins)
pyfor point in data:
.... bin = bisect(bins, point)-1
.... counts[bin] += 1
....
pyfor bin, count in zip(bins,counts):
.... print bin, count
....
0 16
20 71
40 107
60 140
80 170
100 180
120 148
140 110
160 43
180 15
Also, how do reference a specific value for a key in a multipart?It's just a list: the third value is values[2], the last one is
values[-1]...
--
Gabriel Genellina