mixing set and list operations

Ian Kelly ian.g.kelly at gmail.com
Thu Apr 30 18:21:02 CEST 2015

On Thu, Apr 30, 2015 at 10:07 AM, Tim <jtim.arnold at gmail.com> wrote:
> I noticed this today, using Python2.7 or 3.4, and wondered if it is implementation dependent:
> You can use 'extend' to add set elements to a list and use 'update' to add list elements to a set.

It's not implementation dependent. Both methods are documented as
accepting arbitrary iterables. The same is also true for the other
foo_update set methods (and is generally true of built-ins). It is
*not* true for the operator versions of the set methods, however (|,
-, &, ^).

It's also true for dict.update, except that in this case if an
iterable is passed instead of a map, then each element of the iterable
must be a 2-element iterable.

More information about the Python-list mailing list