I'm dealing with such script in python:
In the input I have such array:
a = [2,4,7,2]
On the output I need to return elements of the array, starting with the first one
[2]
[2, 4]
[2, 4, 7]
[2, 4, 7, 2]
How can I retrieve elements, starting with the second and further elements:
//start with a[1]
[4]
[4, 7]
[4, 7, 2]
//start with a[2]
[7]
[7,2]
//start with a[3]
[2]
So, by now my code is looking like this:
def ar(a):
result = 0
res_arr = []
for i in a:
res_arr.append(i)
k = sum(res_arr)
print (res_arr,k)
but I understand, that I need to add external loop, for going through all elements of the array. What is the most efficient way for writing it?