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 1,939 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,040 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
273,766 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
21,441 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,023 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
3,409 views
0 votes
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,040 points
183,527 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,040 points
852 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