Re: mulit-dimensional lists

Discussion in 'Python' started by saoirse_79, Oct 8, 2003.

  1. saoirse_79

    saoirse_79 Guest

    Thanks for your help...what I exactly want to do is as follows: I
    have a file (a multiple sequence alignment to be exact) and I want
    each line in that file to be a separate list, hence creating a list
    of lists!
    saoirse_79, Oct 8, 2003
    #1
    1. Advertising

  2. 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) and I want
    > each line in that file to be a separate list, hence creating a list
    > of lists!


    I'm not clear about how you want to turn each of the lines into a
    list, but that matters only up to a point -- e.g., if you're
    splitting each line on whitespace, then

    listoflists = [ line.split() for line in open('thefile.dat') ]

    would give you the effect you desire.


    Alex
    Alex Martelli, Oct 8, 2003
    #2
    1. Advertising

  3. 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 David Daniels, Oct 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeronimo Bertran

    Mulit-Page database entry form

    Jeronimo Bertran, Nov 11, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    391
    Jeronimo Bertran
    Nov 11, 2003
  2. Alf P. Steinbach
    Replies:
    0
    Views:
    432
    Alf P. Steinbach
    Aug 18, 2003
  3. John Harrison
    Replies:
    4
    Views:
    6,922
    Default User
    Aug 19, 2003
  4. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    400
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  5. Ganapathi sundaram

    Jasper Mulit-Printer Job

    Ganapathi sundaram, Apr 18, 2008, in forum: Java
    Replies:
    0
    Views:
    424
    Ganapathi sundaram
    Apr 18, 2008
Loading...

Share This Page