-1

I have successfully imported a CSV file into a multi-dimensional array in python. What I want to do now is pick specific values from the array and put them into a new single array. For instance if my current arrays were:

[code1, name1, number 1]
[code2, name2, number 2]

I want to select only the code1 and code 2 values and insert them into a new array, because I need to compare just those values to a user input for validation. I have tried using the following:

newvals=[]
newvals.append oldvals([0],[0])

where newvals is the new array for just the codes, oldvals is the original array with all the data and the index [0],[0] refers to code 1, but I'm getting a syntax error. I can't use any add ons as they will be blocked by my admin.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

2 Answers2

0
newvals = []
for i in oldvals:
    newvals.append(i[0])
TheFluffDragon9
  • 514
  • 5
  • 11
0

Usually you can get the first Element in an array a with a[0]. You can create a new array based on another by using the "array for in" syntax

oldData = [[1,2,3],[4,5,6]]
newData = [x[0] for x in oldList]
# newData is now [1,4]
blueOwl
  • 56
  • 4