HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
You can loop through a dictionary by using a
for
loop.
When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as well.
Print all key names in the dictionary, one by one:
for x in thisdict:
print(x)
Print all values in the dictionary, one by one:
for x in thisdict:
print(thisdict[x])
You can also use the values()
function to
return values of a dictionary:
for x in thisdict.values():
print(x)
Loop through both keys and values, by using the
items()
function:
for x, y in thisdict.items():
print(x, y)