On 8/11/06, Terry Peppers <[EMAIL PROTECTED]> wrote:
> I'm really blocked right now, and I don't want to post this to the
> main Python list since I think the answer is probably right in front
> of my face. I'm clearly just too close to see it.
>
> "5100", "foo"
> "5100", "-"
> "5100", "-"
> "5100", "-"
> "5200", "foo"
> "5200", -
>
> That's a total of 6  line records that I want to output like this:
>
> 5100        -         3
> 5100       foo      1
> 5200       -          1
> 5200       foo      1
>
> I want to count the frequency of the second column of data that I can
> access. I can't seem to get any traction as how to figure this out.
> Should I put the data in a list of dictionaries? A dictionary of
> lists? How do I call the data if there are all kinds of duplicate
> keys? When the data's in some data structure how do I iterate over it
> to get frequency of column B?


without hacking any code... i can see two possibilities you can try:

1) easiest.  use a tuple of pairs as your key, i.e. (5100, 'foo'),
(5100, '-'), etc.  it's only confusing because you're seeing "5100" in
both keys

2) more complex.  you suggested a list of dicts or a dict of lists,
but it looks like a dict of dicts would be a better fit., i.e. {5100:
{'foo': 1, '-': 3}, etc.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to