'Does Python set update() replace existing items?
If I use my_set.update(my_list) where some elements of my_list are == existing elements in my_set, does it replace the existing items or not?
Solution 1:[1]
It does not replace existing elements, as can be seen from the following example:
>>> s = {1}
>>> s.add(1.0)
>>> s
{1}
The same behavior holds for dictionary keys:
>>> d = {1: 'foo'}
>>> d.update({1.0: 'bar'})
>>> d
{1: 'bar'}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | a_guest |
