Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Multipart - Counting the amount of Values for One key

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


brennan.ron at gmail

Aug 29, 2008, 10:41 AM

Post #1 of 3 (55 views)
Permalink
Multipart - Counting the amount of Values for One key

hello,

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

Also, how do reference a specific value for a key in a multipart?

Thanks,
Ron



--
FYI, my email address is changing. My rogers account will be deactivated
shortly. From now on please use:
brennan.ron[at]gmail.com


gagsl-py2 at yahoo

Aug 29, 2008, 4:41 PM

Post #2 of 3 (47 views)
Permalink
Re: Multipart - Counting the amount of Values for One key [In reply to]

En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <brennan.ron[at]gmail.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(values))/len(values) # float() to avoid integer division

There are many libraries that provide histogram support, but using the
bisect module may be enough:

... bin = bisect(bins, point)-1
... counts[bin] += 1
...
... 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

--
http://mail.python.org/mailman/listinfo/python-list


claird at lairds

Aug 29, 2008, 5:22 PM

Post #3 of 3 (49 views)
Permalink
Re: Multipart - Counting the amount of Values for One key [In reply to]

In article <mailman.248.1220053320.3487.python-list[at]python.org>,
Gabriel Genellina <gagsl-py2[at]yahoo.com.ar> wrote:
>En Fri, 29 Aug 2008 14:41:53 -0300, Ron Brennan <brennan.ron[at]gmail.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.
.
.
.
Gabriel and other perplexed readers: I *think* the original
questioner has in mind C++'s multimaps <URL:
http://www.cplusplus.com/reference/stl/multimap/ >, imple-
mented, among other places, in the C++ Standard Template
Library. What puzzles *me* is his his insistence, if I
understand him correctly, that Python's lists don't aptly
model multimap containers; from everything I know, a defin-
ing characteristic of multimap containers that they are
strictly ordered. Perhaps someone more current in C++ can
explain.

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.