We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Basically the same thing but within the confines of the printed code that comes when the page is loaded. Slowest = .07 seconds.
Out of curiosity is there a reason you would use the try as opposed to a simple if statement? I am new to python
defpairs(a,k):#a contains array of numbers and k is the value of difference#put all values into a dictionary. If it exists,extractmyDict={item:1forindex,iteminenumerate(a)}count=0foreachinmyDict:ifeach+kinmyDict:count+=1printcountif__name__=='__main__':a=map(int,raw_input().strip().split(" "))_a_size=a[0]_k=a[1]b=map(int,raw_input().strip().split(" "))pairs(b,_k)
Pairs
You are viewing a single comment's thread. Return to all comments →
Basically the same thing but within the confines of the printed code that comes when the page is loaded. Slowest = .07 seconds.
Out of curiosity is there a reason you would use the try as opposed to a simple if statement? I am new to python