Python: Setting tuples from csv file
Question: So essentially what I have is a csv file which is loaded in via some function,
lets call it

    
    
    get_csv
    

So when I have this data, I want to create a new function to format the data
sent from the server into tuples. Which I will call

    
    
    csv_format
    

So assuming the csv comes with 9 columns, how would I set it up so the first
column is an int, the next two are floats and the last ones are strings? I
know this sounds difficult but I hope you can help me out here.

    
    
    def csv_format(data):
    ...
    ....
    return get_csv(data)
    

So essentially I just need to format the tuples so that it outputs like this:

    
    
    (first, second, third, (fourth, fifth, sixth, seventh, eighth, ninth))
    

Thank you in advance


Answer: You should do something like this:

    
    
    import csv
    
    def get_csv(filename):
        with open(filename) as f:
            return list(csv.reader(f))
    
    def csv_format(data):
        return [(row[0], row[1], row[2], tuple(row[3:])) for row in data]
    

## Example

_Input_

    
    
    first,second,third,fourth,fifth,sixth,seventh,eighth,ninth
    

_Output_

    
    
    [('first', 'second', 'third', ('fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth'))]
    

