0
Help with Iterating through dictionaries in list
Ok so I need help. I made 3 dictionaries, then I stored those 3 dictionary variables in a list. Now when I try iterating through that list and into the dictionaries to pull out the key value pairs, an issue happens. It repeats the first user three times instead of each person once. Here is the code I posted: https://code.sololearn.com/czt33NbC8SSq/?ref=app Thanks! 🙏🏽
3 Respostas
+ 1
thanks! i went and re updated the code, i simplified it. Now it works perfectly
0
'if user_1' as a condition means: 'if user_1 evaluates as True...'
And all iterables evaluate as True as long as there's at least one item in it.
That's why you never get to the elifs - user_1 is always True!
(I suspect you will still not get the result you expect - but we'll cross that bridge when we get there.)
0
Since now you do the same operations for all dicts, you could use a loop without problems now:
for user in users:
for key, value in user.items():
print(key.title() + ': ' + value.title())
print("\n")