Which method do you prefer when updating dict?

Asked 2 years ago, Updated 2 years ago, 80 views

When updating and adding elements of a dict object, I don't know how to do it neatly.

I understand that the following 2 methods are possible, which of the two do you prefer?

There may be factors that affect individual tastes, but I'm thinking about it because I feel that both are somewhat messy. ㅜ<

a = {original data}

# Method 1
b = {processed data}
a.update(b)

# Method 2
a[processed data] = c
a[processed data] = d
a[processed data] = e
...

python dictionary

2022-09-20 11:35

1 Answers

I prefer the second one. I think it's more intuitive


2022-09-20 11:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.