Making multidimensional lists in python
Question: This question maybe asked earlier (atleast topic wise) , but still I couldn't
find a solution for my specific problem. Basically, I need a multidimensional
array in python. Such that:

I will be able to access contents in list by :

    
    
    contenets[no_of_record][record]. 
    

So I have a file like :

    
    
    101, Mrs. Jones' Math Class, 10100000001, Jones, Barbara, , , , 10100000011, Gutierrez, Kimberly, 2
    101, Mrs. Jones' Math Class, 10100000001, Jones, Barbara, , , , 10100000013, Mercado, Toby, 1
    101, Mrs. Jones' Math Class, 10100000001, Jones, Barbara, , , , 10100000014, Garcia, Lizzie, 1
    101, Mrs. Jones' Math Class, 10100000001, Jones, Barbara, , , , 10100000015, Cruz, Alex, 1
    

Now I have to maintain a multi dimensional array where no_of_record points to
row number and the record will be the column number.

I want something similar to this:

    
    
    contents=[][]
    
    for lines in source_file:
                    contents[no_of_records][]=lines.rstrip().split(',')
                    print contents[no_of_records]
                    no_of_records+=1
    

I am sure the snippet above is syntactically wrong, I am just trying to give
an idea of what im searching for. Thanks for your help.

-Sethu


Answer: from the csv examples of the doc you should do something along the lines

    
    
    import csv
    rows = []
    with open('some.csv', 'rb') as f:
        reader = csv.reader(f)
        for row in reader:
            print row
            rows.append(row)
    

