My code is
index = 0
for key in dataList[index]:
print(dataList[index][key])
Seems to work fine for printing the values of dictionary keys for index = 0.
But for the life of me I can't figure out how to put this for loop inside a for loop that iterates through the unknown number of dictionaries in dataList
You can easily do this:
It will iterate over the list, and for each dictionary in the list, it will iterate over the keys and print its values.
You could just iterate over the indices of the
range
of thelen
of yourlist
:or you could use a while loop with an
index
counter:you could even just iterate over the elements in the list directly:
It could be even without any lookups by just iterating over the values of the dictionaries:
Or wrap the iterations inside a list-comprehension or a generator and unpack them later:
the possibilities are endless. It's a matter of choice what you prefer.