I'm a little new to Python and have been able to build a pretty nice application over here, but I've been spinning my wheels for a few hours here and I wanted to ask for a little help. Here's my loop where I'm adding to a dictionary:
for toast in checkin_toasts:
if toast['checkin_id'] not in toasts:
toasts[toast['checkin_id']] = {
'user_id': toast['user_id'],
'username': toast['username']
}
else:
toasts[toast['checkin_id']] = toasts[toast['checkin_id']],{
'user_id': toast['user_id'],
'username': toast['username']
}
In my case, I currently have a total of three toasts for two different checkins. The above loop gives me this dictionary:
{8: ({'user_id': 1, 'username': 'shaunwo'}, {'user_id': 2, 'username': 'shaunwo2'}), 9: {'user_id': 1, 'username': 'shaunwo'}}
And then when I try to use it in my jinja form, it works as I would expect for checkin 8 with the two toasts, but it does not work for my checkin 9 that only has one toast. I found that if I manually tweak that dictionary a bit to this:
{8: ({'user_id': 1, 'username': 'shaunwo'}, {'user_id': 2, 'username': 'shaunwo2'}), 9: ({'user_id': 1, 'username': 'shaunwo'},)}
THAT works in my jinja form beautifully. But I don't know how to revise my for loop above accordingly to give me that kind of dictionary with the (,) around the single instance for checkin 9.