Summary grid

Jignesh Sutar jsutar at gmail.com
Wed Jun 22 10:46:35 EDT 2016


Say I have list of data as given in the example code below, I want to find
all the unique categories (alphabetic letters) and unique IDs (numbers) and
then produce a summary grid as manually entered in the "results". How could
I code this?

Many thanks in advance,
Jignesh


data= ["A.1", "A.2", "A.3", "B.1", "C.2", "C.3",  "D.4", "E.5", "E.6"]

cols=[]
rows=[]
for item in data:
    i=item.split(".")
    if i[0] not in cols: cols.append(i[0])
    if i[1] not in rows: rows.append(i[1])

print cols
print rows

results=
[["Row/Col", "A", "B", "C", "D", "E"],
[1, 1, 1, 0, 0, 0],
[2, 1, 0, 1, 0, 0],
[3, 1, 0, 1, 0, 0],
[4, 0, 0, 0, 1, 0],
[5, 0, 0, 0, 0, 1],
[6, 0, 0, 0, 0, 1]]



More information about the Python-list mailing list