Instagram
youtube
Facebook

Q) Write a program in python for,how to find all pairs in list of integers whose sum is equal to given number

Answer:

def findPairs(l, sum):

   for i in range(0, len(l)):
      for j in range(i + 1, len(l)):
         if (l[i] + l[j] == sum):
            print(l[i], l[j])


# driver code
l = [4, 3, 2, -1, 1, 0]
sum = 5

findPairs(l, sum)

 

  • 403 Views

FAQ

Years=[1994,1891,2010,1999,1700,1698,2004] code t…

count=0
years=[1994,1891,2010,1999,1700,1698,2004]
for i in years:
   if(i%4==0 and i%100!=0 o…

ImportError: DLL load failed while importing _cex…

To solve this error you can use . This error came when i worked on matplotlib in python. This is th…

Program to swap variables in python

A program in Python that allows two variables to swap values.

def swap(x, y):

   temp = x
…