# [Tutor] Help with Data representations

kevin parks kp8 at mac.com
Sun Mar 14 23:02:15 EST 2004

```hi all!

I have some data that i want to get a handle on. My data is (so far) is
formatted thusly:

m219a = [5,0,10,7]
m219b = [5,0,10,7,2]
m221a = [5,6]
m221b = [5,6,7]
m222a = [0,10]
m222b = [0,10,2]
m223a = [2,8]

The m291a is the variable name (but i am thinking that it also needs to
be added to the list or the input list turned in to a dictionary?)....
I am not sure what the best way is, but let me first explain what that
data is.. the m291a refers to a point on my time line and the list
contains the values for that item. Sometimes there are more actually a
few items that go on that point on the timeline so that is why there is
a 219a and 219b. The m is just to make it a legal variable name.

So it turns out that i have several hundreds of these items, but only
about 60 or so unique items. I am able to map, sort, and normalize my
data and all the other massaging that i want to do and spit it all out.
Now it turns out that what i really would find helpful is to find out
where each item is in a sort of histogram so that i get a list of all
my 60 or so unique items and each m000x number for where it appears and
finally a tally for how often it appears in a kind of score board. So
that i get something like:

1. [0,10,2] : m222b, m381, m129c : 3
2. [5,6,7] : m221b, m19a, m411b, m367b, m377a : 6

with apologies to the list i will post a much abbreviated version of my
script so that the tutors will better be able to understand my query..

cheers,
kevin

-- snip ---

#!/usr/bin/env python

from normtest import *
from interval import *
from unique2 import unique

def printout(seq):
print '-' * 62
print seq,"\t",step1(seq),"\t",
(min(ordering(rotations(step1(seq))))[3]),"\t",
optional(min(ordering(rotations(step1(seq))))[3])

def test():
m1 = [8, 3, 5, 4]
m7 = [4, 3, 2, 2]
m14 = [8, 3, 7, 5]
m18 = [10, 2, 8, 7]
m20 = [10, 0, 5, 7]
m22 = [10, 2, 8, 7]
m24 = [7, 9, 3, 8]
m28 = [10, 0, 5, 7]
m29 = [10, 11]
m30 = [8, 3, 5, 4]
m32 = [5, 0, 11, 7]
m34 = [8, 3, 7, 9]
m36a = [5, 4, 3, 1]
m36b = [5, 4, 3, 1, 7]
m37a = [0, 8, 2, 4, 9, 10, 1]
m37b = [0, 8, 2, 4, 9, 10, 1, 6]
m39a = [8, 10, 1, 9]
m39b = [8, 10, 1, 9, 7]
m41a = [2, 0, 3, 1]
m41b = [2, 0, 3, 1, 6]
page2 = [m1, m7, m14, m18, m20, m22, m24, m28, m29, m30, m32, m34,
m36a, m36b, m37a, m37b, m39a, m39b, m41a, m41b]
# ~~~~~~~~~~~~~~~~~~~~ page 3 ~~~~~~~~~~~~~~~~~~~~
m43 = [3, 2, 4]
m44a = [0, 8, 2, 4, 9, 10, 1]
m44b = [0, 8, 2, 4, 9, 10, 1, 6]
m45a = [5, 4, 3, 1]
m45b = [5, 4, 3, 1, 7]
m47a = [5,0,3,1]
m47b = [5,4,3,1]
m47c = [5,4,3,1,7]
m49a = [8,10,1,9]
m49b = [8,10,1,9,5]
m51 = [5,0,3,1]
m51b = [5,0,3,1,7]
m53 = [8,3,7,9]
m54a = [5,10,7,0]
m54b = [5,10,7,0, 2]
m55 = [0,8,2,4,9,10,1]
m55b = [0,8,2,4,9,10,1,6]
m57a = [5,0,3,1]
m57b = [5,4,3,1]
m59a = [5,4,3,1]
m59b = [5,4,3,1,7]
m61 = [2,4,3]
m62a = [10,2,8,7]
m62b = [10,2,8,7,0]
m63 = [10,11]
m64 = [8,5,7,10,2]
m64b = [8,5,7,10,2, 9]
m66 = [0,1,6]
m68a = [5,0,3,1]
m86b = [5,0,3,1,7]
m70a = [8,9,10,1]
m70b = [8,9,10,1,7]
m71 = [2,4,11,10]
m72 = [0,1,6,5]
m74 = [8,2,5,4]
m78 = [8,7,10,2]
m80 = [11,8,6,1]
m82a = [7,2,6,8]
m82b = [10,9,0,11]
m82c = [10,9,0,11,4]
m84a = [10,8,2,7]
m84b = [10,8,2,7,0,5]
m85 = [0,1,6,5]
page3 = [m43, m44a, m44b, m45a, m45b, m47a, m47b, m47c, m49a, m49b,
m51, m51b, m53, m54a, m54b, m55, m55b, m57a, m57b, m59a, m59b, m61,
m62a, m62b, m63, m64, m64b, m66, m68a, m86b, m70a, m70b, m71, m72, m74,
m78, m80, m82a, m82b, m82c, m84a, m84b, m85]
# -+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-
all = page2+page3
# tr = []
outlist = []
# first normalize and map everything and pack it in a list
for j in all:
if len(j) > 1:
tr = optional(min(ordering(rotations(step1(j))))[3])
outlist.append(tr)
# now let's find all the unique items
foo = unique(outlist)
unique_item_count = 1
# and then print them out (while counting how many there are)
for item in foo:
print unique_item_count, "\t",item
unique_item_count = unique_item_count + 1
pages = [page2, page3]
pp = 0
for page in pages:
print '=' * 62
print " --- Page ", pp+2, ": "
print '=' * 62
print "set\tmap & sort:\tnormalized:\tto zero:"
pp = pp + 1
# print page
for item in page:
printout(item)

if __name__ == "__main__":
test()

# --

```