tags:

views:

95

answers:

2
c1=[]
      for row in c:
        c1.append(row[0:13])

c is a variable containing a csv file

i am going through every row in it and i want only the first 14 elements to be in the c1

what am i doing wrong?

+2  A: 

Nicer:

c1= [row[:13] for row in c.readlines()]

if that doesn't work, you may not assigning to c properly.

Also keep in mind that if you want first 14 characters, you actually want to do row[:14] Then you get characters 0->13 inclusively, or 14 total.

karpathy
thank you very much, actually it's not characters it is a list
I__
+2  A: 

That will not include the element indexed at [13].

c1=[]
  for row in c:
    c1.append(row[:14])

If you want the individual elements (the above code will append a list, much like a 2D array) you should append it in the following way:

    c1 += row[:14]