Iterators in python

what if i want to perform any task or function on the values of the dictionary rather than keywords. Then how will i get the values from the dictonary?

Hello @Ishika_jain,

d = {"bat":1, "ball":2, "cat":3, "dog":4}
for key, value in d.items():
    print(key)
    print(value)

Output:

bat
1
ball
2
cat
3
dog
4

As you have seen here, to access key as well as the values from a dictionary, you can iterate over dict.items().

Hope this was what you were looking for.
Happy Learning :slight_smile:
Thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.