[Tutor] histogram type thingy for dict items

John Purser johnp at HomeLumber.com
Mon Mar 29 10:38:10 EST 2004


Kevin,

I didn't see the original post but I think this is pretty straight forward and works on windows, Python 2.3.

p = { (287, 0) : [0, 7],(287, 1) : [0, 7, 2],(288, 0) : [ 3, 8 ],(288, 1) : [ 3, 8, 6 ],(291, 0) : [ 3, 7 ],(291, 1) : [ 6, 3, 7 ],(292, 0) : [ 3, 7 ],(293, 0) : [0, 7],(294, 0) : [ 3, 8 ],(295, 0) : [ 3, 4 ],(295, 1) : [0, 7] }
>>> n = {}
>>> for key in p.keys():
... 	try:
...		n[tuple(p[key])].append(key)
... 	except KeyError:
... 		n[tuple(p[key])] = [key]
... 		
>>> n
{(3, 7): [(291, 0), (292, 0)], (3, 4): [(295, 0)], (3, 8): [(294, 0), (288, 0)], (0, 7, 2): [(287, 1)], (0, 7): [(287, 0), (295, 1), (293, 0)], (3, 8, 6): [(288, 1)], (6, 3, 7): [(291, 1)]}

John Purser

-----Original Message-----
From: kevin parks [mailto:kp8 at mac.com]
Sent: Monday, March 29, 2004 1:14 AM
To: tutor at python.org
Subject: [Tutor] histogram type thingy for dict items


Hi all... Me again... *^-^* ... i'll try to make this the last one for 
a while. I've been at it pretty
hard and one more important question.

As you know.. :] i have been mucking with a lot of data in a dictionary 
that looks like:


page08 = { (287, 0) : [0, 7],
	(287, 1) : [0, 7, 2],
	(288, 0) : [ 3, 8 ],
	(288, 1) : [ 3, 8, 6 ],
	(291, 0) : [ 3, 7 ],
	(291, 1) : [ 6, 3, 7 ],
	(292, 0) : [ 3, 7 ],
	(293, 0) : [0, 7],
	(294, 0) : [ 3, 8 ],
	(295, 0) : [ 3, 4 ],
	(295, 1) : [0, 7],
  }

pages and pages of it. The tuple represents a point time and the lists 
are my values for that time. It happens
that there are many times that have the same data values [the list 
items are the same]... what i want to do
now is take each unique value list (there are only 57 of them as my 
unique.py mod reports) and tell me
where they occur so that (just looking at that little slice above) i 
would get (hope i don't mess thus up):

[0, 7]       --> (287, 0), (293, 0), (295, 1)
[0, 7, 2]   --> (287, 1)
[ 3, 8 ]     --> (288, 0), (294, 0)
[ 3, 8, 6 ] --> (288, 1)
[ 3, 7 ]      --> (291, 0), (292, 0)
[ 6, 3, 7]  --> (291,1)
[ 3, 4 ] --> (295, 0)


I other words i want a sort of histogram of each unique event telling 
me at what key they happen
and how many of each unique event there is.

Now... I know that i used to have a magic little piece of code that 
does that very thing ... and i am pretty sure
that it was Danny Yoo that help me with that, or posted it, wonderfully 
commented, to the list. I save all kind
of things from this list! But not too long ago i lost everything when 
my hard drive gave out and not all
my python stuff was backed up.

i've searched 
http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/python-Tutor and 
the cookbook
and i don't see anything and a google turns up some crazy 
incomprehensible very advanced bells and
whistles graphic things that just is a heck of a lot more than i can 
wrap my pea sized brain around and is
just way more than i need.

So, if anyone has such a beast or wants to help me get started i would 
be grateful. To be honest i am
kind of sending this in desperation *^-^* (no it's not for homework)

incidentally there used to be a humongous mbox file of the entire tutor 
list archive that you could grep,
is that gone?

cheers,
kevin




_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list