Easy question

Terry Reedy tjreedy at udel.edu
Wed Apr 11 17:09:57 EDT 2001


> I need to read some data from a file.  Each (tab delimited) row
corresponds
> to an array index eg.

> 0    0    0    0    0    0
> 0    1    0    0    0    0
> 0    0    1    0    0    0

> And I need something like,
> [[0,0,0,0,0,0], [0,1,0,0,0,0], [0,0,1,0,0,0], ...]
> What's the best way of doing this?  Cheers in advance.

Easy (pseudocode) answer:

result = []
for each line (read 1 at a time or all at once), split on \t and append to
result

If need to (not clear) convert '0','1' strings to 0, 1 numbers.

TJR





More information about the Python-list mailing list