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,020 points

retagged Jul 5, 2019 by Kalgi 2,392 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
• 3,050 points

Related Questions In Python

+1 vote
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
281,599 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 13, 2019 in Python by Usha
22,465 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

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

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,070 views
+1 vote
4 answers

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
• 3,050 points
188,462 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
• 3,050 points
1,116 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP