mulit-dimensional lists

Scott David Daniels Scott.Daniels at Acm.Org
Wed Oct 8 11:36:19 EDT 2003


saoirse_79 wrote:
> 
> Thanks for your help...what I exactly want to do is as follows: I 
> have a file (a multiple sequence alignment to be exact) 
This describes your input to you, but not to me.  Try a very concrete
description with an example.
I'll guess:
     My file looks like:
     1 2 3
     3
     4 5 6
     ...
 > and I want each line in that file to be a separate list, hence
 > creating a list of lists!
Again, I'll guess you mean:
     [[1, 2, 3],
      [3],
      [4, 5, 6]
      ...]

After:
     f = file(sourcefilename, 'r')
     result = []
     for line in f:
         result.append(line.split())
     f.close()

result[5] is the list resulting from splitting the sixth line of the file.


-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list