Answers for "Finding the Sum of a Symmetrical Sub-List"

0

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))
Posted by: Guest on October-25-2021

Code answers related to "Finding the Sum of a Symmetrical Sub-List"

Python Answers by Framework

Browse Popular Code Answers by Language