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, 2019 in Python by Neel
• 3,010 points

retagged Jul 5, 2019 by Kalgi 26 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, 2019 by Arvind
• 2,980 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, 2019 in Python by Esha
1,926 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, 2019 in Python by Usha
115 views
0 votes
1 answer
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 530 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 2,980 points
399 views
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, 2019 in Python by Arvind
• 2,980 points
98 views