Re: Multipart - Counting the amount of Values for One key

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    Re: Multipart - Counting the amount of Values for One key

    En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <brennan.ron@gm ail.com>
    escribi�:
    I am trying to find the amount of values there are pertaining to one key.
    >
    For example:
    >
    - To find the average of the values pertaining to the key.
    - Use the amount of values to calculate a histogram
    What is a "multipart" ? I know MIME multipart messages but they don't seem
    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(value s))/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

  • Cameron Laird

    #2
    Re: Multipart - Counting the amount of Values for One key

    In article <mailman.248.12 20053320.3487.p ython-list@python.org >,
    Gabriel Genellina <gagsl-py2@yahoo.com.a rwrote:
    >En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <brennan.ron@gm ail.com>
    >escribi�:
    >
    >I am trying to find the amount of values there are pertaining to one key.
    >>
    >For example:
    >>
    >- To find the average of the values pertaining to the key.
    >- Use the amount of values to calculate a histogram
    >
    >What is a "multipart" ? I know MIME multipart messages but they don't seem
    >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.

    Comment

    Working...