Let's print all dictionary keys to the screen. To do this, we'll run our list through a loop twice:
You can also use a loop to iterate over a multidimensional list of dictionaries. Let's say we have the following list:
lst = [
{
'a': 1,
'b': 2,
},
{
'c': 3,
'd': 4,
},
{
'e': 5,
'f': 6,
},
]
You can also use a loop to iterate over a multidimensional list of dictionaries. Let's say we have the following list:
for sub in lst:
for key in sub:
print(key)
Find the sum of all numbers using a loop.
lst = [
{
'a': 1,
'b': 2,
'c': 3
},
{
'a': 4,
'b': 5,
'c': 6
},
{
'a': 7,
'b': 8,
'c': 9,
},
]
Find the sum of all numbers using a loop.
Let's print all dictionary keys to the screen. To do this, we'll run our list through a loop twice:
'a' 1
'b' 2
'c' 3
'a' 4
'b' 5
'c' 6
'a' 7
'b' 8
'c' 9