← Back to context

Comment by peter422

1 day ago

I love the union syntax in 3.9+:

  new_dict = old_dict | update_keys_and_values_dict

Don’t forget the in place variant!

  the_dict |= update_keys_and_values_dict

  • No no, do forget about it: like += for lists, |= mutates “the dict”, which often makes for awkward bugs.

    And like += over list.extend, |= over dict.update is very little gain, and restricts legal locations (augmented assignments are statements, method calls are expressions even if they return "nothing")