Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python sum of a subset

n,su = map(int,input().split())
A = list(map(int,input().split()[:n]))
s = []
for i in range(0,len(A)+1):
    for j in range(i+1,len(A)+1):
        s.append(A[i:j])
        
for k in s:
    if sum(k) == su:
        f = 1
        break
if f == 1:
    print("TRUE")  
else:
    print("FALSE")
Comment

PREVIOUS NEXT
Code Example
Python :: convert pandas group to dict 
Python :: make a post request in python 
Python :: python pandas shape 
Python :: python is space 
Python :: python extract email attachment 
Python :: len in python 
Python :: create virtualenv python3 
Python :: matplotlib savefig cutting off graph 
Python :: How to Get the Union of Sets in Python 
Python :: python select last item in list 
Python :: python 2.7 venv 
Python :: dataframe of one row 
Python :: modern tkinter 
Python :: cv2 opencv-python imshow while loop 
Python :: global variables python 
Python :: pandas rolling mean 
Python :: Check if file already existing 
Python :: convert list of lists to pandas dataframe 
Python :: character to ascii python 
Python :: string upper lower count python 
Python :: run python command 
Python :: django template render dict 
Python :: change base python 
Python :: username python system 
Python :: python call function x number of times 
Python :: eval function in python 
Python :: python generator expression 
Python :: python for loop index 
Python :: django login 
Python :: python variable scope 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =