Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | Pair Product combinations
Next article icon

Python – Minimum Product Pair in List

Last Updated : 24 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Sometimes, we need to find the specific problem of getting the pair that yields the minimum product, this can be solved by sorting and getting the first and second elements of the list. But in some case, we don’t with to change the ordering of list and perform some operation in the similar list without using extra space. Let’s discuss certain ways in which this can be performed.
Note: All elements in the list are positive integer.

Method #1 : Using list comprehension + min() + combination() + lambda This particular task can be performed using the combination of above functions in which we use list comprehension to bind all the functionalities and min function to get the minimum product, combination function finds all product internally and lambda function is used to compute the product. 

Python3




# Python3 code to demonstrate
# Minimum Product Pair in List
# using list comprehension + min() + combinations() + lambda
from itertools import combinations
 
# initializing list
test_list = [3, 4, 1, 7, 9, 1]
 
# printing original list
print("The original list : " + str(test_list))
 
# using list comprehension + min() + combinations() + lambda
# Minimum Product Pair in List
res = min(combinations(test_list, 2), key = lambda sub: sub[0] * sub[1])
 
# print result
print("The minimum product pair is : " + str(res))
 
 
Output : 
The original list : [3, 4, 1, 7, 9, 1] The minimum product pair is : (1, 1)

Time Complexity: O(n*n), where n is the number of elements in the list “test_list”.
Auxiliary Space: O(n), where n is the number of elements in the list “test_list”.

Method #2 : Using list comprehension + nsmallest() + combination() + lambda This method has potential of not only finding a single minimum but also k minimum product pairs if required and uses nsmallest function instead of min function to achieve this functionality. 

Python3




# Python3 code to demonstrate
# Minimum Product Pair in List
# using list comprehension + nsmallest() + combinations() + lambda
from itertools import combinations
from heapq import nsmallest
 
# initializing list
test_list = [3, 4, 1, 7, 9, 8]
 
# printing original list
print("The original list : " + str(test_list))
 
# using list comprehension + nsmallest() + combinations() + lambda
# Minimum Product Pair in List
res = nsmallest(2, combinations(test_list, 2), key = lambda sub: sub[0] * sub[1])
 
# print result
print("The minimum product pair is : " + str(res))
 
 
Output : 
The original list : [3, 4, 1, 7, 9, 8] The minimum product pair is : [(3, 1), (4, 1)]

Time Complexity: O(n*n), where n is the number of elements in the list “test_list”.
Auxiliary Space: O(n), where n is the number of elements in the list “test_list”.



Next Article
Python | Pair Product combinations
author
manjeet_04
Improve
Article Tags :
  • Python
  • Python Programs
  • Python list-programs
Practice Tags :
  • python

Similar Reads

  • Python | Maximum of Product Pairs in Tuple List
    Sometimes, while working with data, we might have a problem in which we need to find maximum product between available pairs in list. This can be application to many problems in mathematics domain. Let’s discuss certain ways in which this task can be performed. Method #1 : Using max() + list compreh
    5 min read
  • Python | Product of Prefix in list
    Nowadays, especially in competitive programming, the utility of computing prefix product is quite popular and features in many problems. Hence, having a one-liner solution to it would possess a great help. Let’s discuss certain ways in which this problem can be solved. Method 1: Using list comprehen
    4 min read
  • Python - Find Minimum Pair Sum in list
    Sometimes, we need to find the specific problem of getting the pair which yields the minimum sum, this can be computed by getting initial two elements after sorting. But in some case, we don’t with to change the ordering of list and perform some operation in the similar list without using extra spac
    4 min read
  • Python - Pair with Maximum product
    Sometimes, we need to find the specific problem of getting the pair which yields the maximum product, this can be computed by getting initial two elements after sorting. But in some case, we don’t with to change the ordering of list and perform some operation in the similar list without using extra
    6 min read
  • Python | Pair Product combinations
    Sometimes, while working with data, we can have a problem in which we need to perform tuple multiplication among all the tuples in list. This can have application in many domains. Let’s discuss certain ways in which this task can be performed. Method #1 : Using combinations() + list comprehension Th
    4 min read
  • Python - Product of consecutive pairs in list
    Sometimes, while working with Python list, one can have a problem in which one needs to find perform the product of list in pair form. This is useful as a subproblem solution of bigger problem in web development and day-day programming. Let’s discuss certain ways in which this problem can be solved.
    7 min read
  • Python - Cubes Product in list
    Python being the language of magicians can be used to perform many tedious and repetitive tasks in a easy and concise manner and having the knowledge to utilize this tool to the fullest is always useful. One such small application can be finding product of cubes of list in just one line. Let’s discu
    5 min read
  • Python - Maximum Quotient Pair in List
    Sometimes, we need to find the specific problem of getting the pair which yields the maximum Quotient, this can be solved by sorting and getting the first and last elements of the list. But in some case, we don’t with to change the ordering of list and perform some operation in a similar list withou
    5 min read
  • Python | Consecutive Pair Minimums
    Sometimes, while working with Python list, one can have a problem in which one needs to find perform the minimum of list in pair form. This is useful as a subproblem solution of bigger problem in web development and day-day programming. Let’s discuss certain ways in which this problem can be solved.
    5 min read
  • Python | Sliced Product in List
    Accessing elements in a list has many types and variations. These are an essential part of Python programming and one must know to perform the same. This article discusses ways to fetch the initial K elements and do its multiplication. Let’s discuss a certain solution to perform this task. Method #1
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences