eeyyyyyy fellow python spice enjoyers, what would you say is more "readable" / straight-forward for a nested dictionary creation/update scenario?

a = {} b = "pumpkin" c = "spice" if b in a: a[b][c] = True else: a[b] = {c: True}vsa = {} b = "python" c = "spice up ya life" a.update({b: {c: True}})
the second one is definitely less code but I feel like it's... a tich too clever. Or do people often use that second approach? I've classically stuck to the first one but.

Assume it will be read by non-python experts, as well, but that visually things are getting a little cluttered so maybe condensing some things would be nice...

#python #pythonQuestions

@aud Beware that those are not equivalent. The first one will keep the other keys in 'b' if there are any, the second will update 'b' to be a dictionary with a single 'c' key.

So it all depends what you want to do.

@nicoe ohhhhh, you're right. Hadn't even considered that angle.

And in fact, I think that IS relevant here. Good catch, thank you!
@nicoe Yeah; not only is defaultdict() the cleaner option, readability wise... but it also maintains the behavior in example A without writing over it ala example B.

Part of the issue is these are loop variables running over an opened file whose format I'm only haltingly familiar with, so I had totally missed that yes, in fact, it's potentially possible the nested dictionaries need to have more than one value...