in Python by (31.7k points)
How Do You Traverse Through A Dictionary Object In Python?

1 Answer

0 votes
by (23.9k points)
We can use the “for” and “in” loop for traversing the dictionary object.

>>> site_stats = {'site': '', 'traffic': 10000, "type": "organic"}

>>> for k, v in site_stats.items():

    print("The key is: %s" % k)

    print("The value is: %s" % v)


The output is:

The key is: type

The value is: organic


The key is: site

The value is:


The key is: traffic

The value is: 10000


Related questions

+1 vote
asked Feb 13, 2021 in Python by SakshiSharma (32.2k points)
0 votes
asked Dec 19, 2019 in Python by sharadyadav1986 (31.7k points)
0 votes
asked Aug 30, 2020 in Python by sharadyadav1986 (31.7k points)