How to store "3D" data? (data structure question)

Cyril Bazin cyril.bazin at
Wed Jul 20 21:52:15 CEST 2005

The question of the type of the data sutructure depends of your use of the 
You could avoid some confusion without naming your columns "lines"...

Anyway, here is a piece of code that read the file and count the star on the 
(The result is a dict of dict of int.)

import itertools
import csv

f = open("") #change your file name
lineReader = csv.reader(f)

#Set the lines titles (RHA280, etc)
l = 
linesTitles = l[2:]

#We construct the data structure and count the stars on the fly
datas = {}
for l in lineReader:
name, allele = l[:2]
if not allele: #empty line
if name: #new block defining a TD*
currentName = name
d = dict.fromkeys(linesTitles, 0)
datas[currentName] = d
lines = l[2:]
#add 1 to the lines not empty (<=> with a star)
for title, value in itertools.izip(linesTitles,lines): 
if value:
d[title] += 1

#little tests
print datas
print datas["TDF1"]["RHA280"]
print datas["TDF3"]["RHA280"]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list