(Jun-07-2023, 01:06 AM)Skaperen Wrote: i want to increment the object. i can do this when i get it directly from a dict like so:
cars_per_train[which_train] += 1 # one car passes by so count it.
If the value in that dict is an immutable object (like an int), then you can't really increment that object. Instead, a different object will be assigned to that key in the dict. As such, it's unclear if you really want just the int object, as it cannot be changed.
If the value is mutable, then incrementing is possible. In that case, just return the value.