How to access the elements of a dictionary using index ?

0 votes
I am new to Python. How to access the elements of a dictionary using indexes?
Jul 4 in Python by Neel
• 3,010 points

retagged Jul 5 by Kalgi 13 views

1 answer to this question.

0 votes
Suppose you have a dictionary

num = {'physics': 80, 'math': 90, 'chemistry': 86}

You can use the following code to access the elements -

print(list(num.keys())[0])  # returns  1st key
print(list(num.values())[0]) # returns value of 1st key
print(list(num.items())[0]) #Returns a list of dict’s (key, value) tuple pairs
answered Jul 4 by Arvind
• 2,960 points

Related Questions In Python

0 votes
1 answer

How to find the index of a particular value in a dataframe?

First, use the dataframe to match the ...READ MORE

answered Apr 8 in Python by Esha
339 views
0 votes
1 answer

How to print the index of a Pandas Dataframe?

You can do this using the code ...READ MORE

answered May 12 in Python by Usha
46 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 230 views
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer

How to create a dictionary whose elements are lists?

A simple way to do this is ...READ MORE

answered Aug 7 in Python by Arvind
• 2,960 points
55 views