Let's suppose you have a python list and want to convert it to an array. The most straight forward way would be to use a for loop.
And that's what I've been doing most of the time, but it clutters the code with basic operations, and I know cython is compiled python so I wonder if there's a shorthand or more pythonic way of doing it.
list = [i for i in range(10)]
cdef int * array = <int *> malloc(sizeof(int) * 10)
cdef int i
for i in range(len(list)):
array[i] = list[i]
Is there any syntax that allows me to perform this copy in one single line?
This doesn't seem to work:
array[:] = list[:]