in Python by
Q:
How Do You Traverse Through A Dictionary Object In Python?

1 Answer

0 votes
by
We can use the “for” and “in” loop for traversing the dictionary object.

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

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

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

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

    print("++++++++++++++++++++++++")

The output is:

The key is: type

The value is: organic

++++++++++++++++++++++++

The key is: site

The value is: tecbeamers.com

++++++++++++++++++++++++

The key is: traffic

The value is: 10000

++++++++++++++++++++++++

Related questions

+1 vote
asked Feb 13 in Python by SakshiSharma
0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
...