I have two sql queries, which I store in two arrays each; my first array contains 23 positions and the second 17, but I want to bring only certain positions from the second to the first.
What I can think of is to go through the first array (CutPoint) and look for the value of position [0] in the second array (Validations) and call the positions that I want.
This is my code, what I have tried.
def Base_adherencia():
apro = PuntoDeCorte()
val = Validaciones()
base = []
## CREANDO ARREGLO BASE
for row in apro:
base.append(row)
## AGREGANDO VALIDACIONES AL ARREGLO BASE
print("AGREGANDO VALIDACIONES AL ARREGLO BASE")
for row in val:
a = base[0]
b = val [0]
if a == b:
base.append(val[1,2,3,4,5,6,7,8,9,11,12,13,14,16,17])
for row in base:
print(row)
Something like this would be expected:
I created the example functions
In python 3.6 onwards, you can concatenate lists with '+'
on the other hand, comment that you can index arrays in python using
:
for example:a[:]
is the whole array (the same as writinga
) but for example you could say the whole array starting from the second elementa[1:]
and the general notation isa[start:end:step]
wherestart
is the starting index of the array (python arrays start at 0)end
the last value andstep
is the jump or step.It can also be indexed "negatively" for example
a[-1]
it is the last element,a[-2]
the next to last and so on (and negative indices can be used for trimming with:
)I hope the code will help you
The lists that will be used to integrate values are made.
Then we create our function in set of two arguments.
Next we make 2 For loops to be able to go through and add values to the lists and we increase it +1, since the for removes 1 more number Eg: if it is done from 1 to 10 it will call you a 9 instead of 10, and we start from the 0.
Finally we perform the print (show in console).
We concatenate (join) 2 lists to be 1 with the .extend() method, it is also possible to concatenate lists with "+" Ex: list = list1 + list2.
At this point we will show the strings in the console and 1 method .index(2), it is used to find the exact position of a number.
To finish we declare the function and call the values of the arguments of the function, in this case 10 and 20, do not put one more and not one less as it will cause an error.