Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to find a pair with maximum product from int list in Python

2 Answers

0 votes
def max_product_from_int_list(arr):
    it1 = lst[0]
    it2 = lst[1]
    l = len(lst)
    
    for i in range(0, l):
        for j in range(i + 1, l):
            if (lst[i] * lst[j] > it1 * it2):
                it1 = lst[i] 
                it2 = lst[j]
                
    return it1, it2
 
 
lst = [3, 9, 1, 3, 7, 0, 8, 4]
tem1 = 0
item2 = 0
      
item1, item2 = max_product_from_int_list(lst)
      
print(item1, item2)
  
  
   
'''
run:
   
9 8
   
'''

 



answered Apr 15, 2019 by avibootz
edited Dec 26, 2025 by avibootz
0 votes
def max_product_pair(lst):
   if len(lst) < 2:
       return "No pairs exist"
   
   lst.sort()
   
   product1 = lst[0] * lst[1]
   product2 = lst[-1] * lst[-2]
   if product1 > product2:
       return (lst[0], lst[1])
   else:
       return (lst[-2], lst[-1])


lst = [3, 9, 1, 3, 7, 0, 8, 4]

print(max_product_pair(lst)) 


'''
run:

(8, 9)

'''

 



answered Dec 26, 2025 by avibootz
...