Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I'm quite new to the entirety of this so this may be a noobie question.. be that as it may, I am hoping to discover the length of dictionary esteems... however, I don't have the foggiest idea how this should be possible.

For example:

d = {'key':['hello', 'brave', 'morning', 'sunset', 'metaphysics']}

I was just wondering is there a way I can discover the len or number of things of the dictionary esteem. 

Thanks

1 Answer

0 votes
by (26.4k points)

Sure. For this situation, you'd simply do:

length_key = len(d['key'])  # length of the list stored at `'key'` ...

It's difficult to say why you really need this, in any case, maybe it is helpful to make another dict that maps the keys to the length of qualities:

length_dict = {key: len(value) for key, value in d.items()}

length_key = length_dict['key']  # length of the list stored at `'key'` ...

Interested to learn python in detail? Come and Join the python course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...