ItSolutionStuff.com

How to Get First Value in Dictionary Python?

By Hardik Savani • October 30, 2023
Python

Hi Friends,

In this tute, we will discuss python dictionary get first value. we will help you to give an example of how to get first value in dictionary python. you can see how to get first value in python dictionary. I explained simply about python 3 get first value in dict.

We will get first value from python dictionary using next() and iter() functions. So, without further ado, let's see simple examples: You can use these examples with python3 (Python 3) version.

Example:

main.py

# Create New Dictionary Object
myDictionary = {
  "id": 1,
  "name": "Hardik Savani",
  "email": "hardik@gmail.com"
}
  
# Get First Item from Dictionary
firstPair = next(iter((myDictionary.items())) )
  
print('First Key Value Pair of Dictionary is:')
print(firstPair)
 
print('First Key: ', firstPair[0])
print('First Value: ', firstPair[1])

Output:

First Key Value Pair of Dictionary is:
('id', 1)

First Key:  id
First Value:  1

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Convert Dictionary to JSON in Python?

Read Now →

Python Dictionary Convert Keys to List Example

Read Now →

How to Convert Dictionary Values into List in Python?

Read Now →

How to Convert Dictionary to List in Python?

Read Now →

How to Get Length of Dictionary Python?

Read Now →

Python Dictionary Remove Duplicate Values Example

Read Now →

Python Dictionary Check if Value is Empty Example

Read Now →

How to Check if Python Dictionary is Empty or Not?

Read Now →

Check if Key Value Pair Exists in Dictionary Python Example

Read Now →

Python Dictionary Check if Value Exists Example

Read Now →

Python Dictionary Check if Key Exists Example

Read Now →

How to Update Value in Python Dictionary?

Read Now →

How to Change Value in Python Dictionary?

Read Now →

Python Dictionary Remove Element by Value Example

Read Now →