Python - from file to data structure?

Posted by Seafoid on Stack Overflow See other posts from Stack Overflow or by Seafoid
Published on 2010-05-28T12:22:59Z Indexed on 2010/05/28 12:31 UTC
Read the original article Hit count: 221

Filed under:
|
|
|

Hi,

I have large file comprising ~100,000 lines. Each line corresponds to a cluster and each entry within each line is a reference i.d. for another file (protein structure in this case), e.g.

1hgn 1dju 3nmj 8kfn
9opu 7gfb 
4bui

I need to read in the file as a list of lists where each line is a sublist, thus preserving the integrity of the cluster, e.g.

nested_list = [['1hgn', '1dju', '3nmj', '8kfn'], ['9opu', '7gfb'], ['4bui']]

My current code creates a nested list but the entries within each list are a single string and not comma separated. Therefore, I cannot splice the list with indices so easily.

Any help greatly appreciated.

Thanks, S :-)

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner