Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Finding the Sum of a Symmetrical Sub-List

import numpy as np

def symmetrical_sum (arr):
    l = len(arr)-1
    bool_arr = np.array([x==arr[l-i] for i,x in enumerate(arr)])
    idx_arr = np.where(bool_arr==True)[0]
    if len(idx_arr):
        res = arr[min(idx_arr):max(idx_arr)+1]
    else:
        res = []
    return (res, sum(res))
 
PREVIOUS NEXT
Tagged: #Finding #Sum #Symmetrical
ADD COMMENT
Topic
Name
2+6 =