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
• 1,610 points

retagged Jul 5 by Kalgi 6 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
• 1,530 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
122 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
29 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 128 views
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer

how to check the syntax of python program without running the program?

Yes, it is possible to check the ...READ MORE

answered Jun 27 in Python by Arvind
• 1,530 points
20 views