Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110318

Summary grid

From Jignesh Sutar <jsutar@gmail.com>
Newsgroups comp.lang.python
Subject Summary grid
Date 2016-06-22 14:46 +0000
Message-ID <mailman.40.1466606829.11516.python-list@python.org> (permalink)
References <CACvW2fz29iNOxe0E0ZrqZU7=ov6s0VZbB_2bLFG37WqgOZEPrw@mail.gmail.com>

Show all headers | View raw


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]]

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Summary grid Jignesh Sutar <jsutar@gmail.com> - 2016-06-22 14:46 +0000
  Re: Summary grid Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-06-22 18:43 +0300

csiph-web