Apr-25-2017, 08:10 PM
I have a list of values [abc123, abc123, abc123, abc123, etc..]
I want to input that list into a CSV whereby the first 3 characters of each index are in the first column.
i.e
I need the data structured in the cvs like follows:
col1 col2 col3 col4
abc 1 2 3
abc 1 2 3
abc 1 2 3
I've created a csv with headers as follows:
I need to iterate through the list but I'm stuck on how to place rows and columns. Keep getting stuck. The closest to any solution i've got to is this but its way off..
I want to input that list into a CSV whereby the first 3 characters of each index are in the first column.
i.e
1 2 3 4 5 6 |
list = [abc123, abc123, abc123, abc123] for i in list : first_3 = i[: 3 ] the_rest = i[ 3 :] |
I need the data structured in the cvs like follows:
col1 col2 col3 col4
abc 1 2 3
abc 1 2 3
abc 1 2 3
I've created a csv with headers as follows:
1 2 3 4 5 |
file = open ( 'test.cv' , 'w' ) file .write( 'First col' ) for h in range ( 0 , 4 ): file .write( 'Col' + str (h) + "," ) file .write( '\n' ) |
1 2 3 4 |
for i in range ( 0 , len ( list ) for j in range ( 0 , len ( list [i]): file .write( list [i][j] + "," file .write( "\n" ) |