How to Find MIN and MAX Value in a Dictionary Using Python?

Practice Python effectively by following this step-by-step tutorial on how to get min and max values in a dictionary using Python. | ProjectPro

Python dictionaries are versatile data structures that efficiently store and retrieve key-value pairs. Often, you might need to find the minimum and maximum values within a dictionary. This tutorial helps you understand how to get the MAX and MIN values in a dictionary using Python. 

How to Find MAX Value in a Dictionary Using Python?

If you want to find the maximum value in a dictionary, you can utilize the max() function and a lambda function to specify the key based on which the maximum value should be determined. Check the example below to get a clear understanding - 

How to Get Key with MAX Value in a Dictionary Using Python? 

If we also need to retrieve the key associated with the maximum value in the dictionary, we can use a dictionary comprehension along with the max() function. Here’s how - 

How to Find MIN Value in a Dictionary Using Python? 

Similarly, finding the minimum value in a dictionary can be done using the min() function along with a lambda function or directly applying min()on the dictionary's values. For example:

How to Find Maximum and Minimum Values in a Matrix? 

Step 1 - Import the library

    import numpy as np

We have only imported numpy which is needed.

Step 2 - Setting up the Matrix

We have created a 4 x 4 matrix using arrays.

    matrix_101 = np.array([[10, 11, 12, 23],

                       [4, 5, 6, 25],

                       [7, 8, 9, 28],

                       [1, 2, 3, 41]])

Step 3 - Finding Maximum and Minimum Value

We can find the maximum and minimum values by using the function max and min respectively. We can also pass axes as a parameter which will help us to find maximum or minimum values of every row and column.

    print(np.max(matrix_101))

    print(); print(np.min(matrix_101))

    print(np.max(matrix_101, axis=0))

    print(); print(np.max(matrix_101, axis=1))

So the output comes as

41

1

[10 11 12 41]

[23 25 28 41]

Get Access to Python Projects Through ProjectPro! 

Gaining practical experience through real-world projects is paramount in mastering Python and its applications, especially in data science and big data. ProjectPro offers access to a diverse range of Python projects that enable learners to apply their knowledge in tangible ways. With ProjectPro, learning becomes more than just theory—it transforms into a hands-on experience, allowing individuals to experiment, troubleshoot, and ultimately deepen their understanding of Python. So why settle for mere comprehension when you can actively engage with Python concepts through ProjectPro? 

Download Materials

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

MLOps Project on GCP using Kubeflow for Model Deployment
MLOps using Kubeflow on GCP - Build and deploy a deep learning model on Google Cloud Platform using Kubeflow pipelines in Python

BigMart Sales Prediction ML Project in Python
The goal of the BigMart Sales Prediction ML project is to build and evaluate different predictive models and determine the sales of each product at a store.

Learn How to Build PyTorch Neural Networks from Scratch
In this deep learning project, you will learn how to build PyTorch neural networks from scratch.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Loan Eligibility Prediction in Python using H2O.ai
In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

Learn Object Tracking (SOT, MOT) using OpenCV and Python
Get Started with Object Tracking using OpenCV and Python - Learn to implement Multiple Instance Learning Tracker (MIL) algorithm, Generic Object Tracking Using Regression Networks Tracker (GOTURN) algorithm, Kernelized Correlation Filters Tracker (KCF) algorithm, Tracking, Learning, Detection Tracker (TLD) algorithm for single and multiple object tracking from various video clips.

NLP Project for Multi Class Text Classification using BERT Model
In this NLP Project, you will learn how to build a multi-class text classification model using using the pre-trained BERT model.

PyTorch Project to Build a LSTM Text Classification Model
In this PyTorch Project you will learn how to build an LSTM Text Classification model for Classifying the Reviews of an App .