Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Search for a symmetrical inner elements of a list python

def symmetrical_sum(a):
    dup=[x for n, x in enumerate(a) if x in a[:n]] #to get the duplicate
    
    to_int = int(''.join(map(str,dup))) #change duplicate into int
    dup1_index=a.index(to_int) #index the first duplicate
    dup2_index=a.index(to_int,dup1_index+1) #index the second duplicate
    portion=a[dup1_index:dup2_index+1] #get the symetric portion
    total = sum(portion) #sum the elements in portion
    tuple1 = (portion,total) #create tuple
    return tuple1
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Search #symmetrical #elements #list #python
ADD COMMENT
Topic
Name
1+7 =