Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #89637

Re: mixing set and list operations

References <7f1dc7d2-2f88-4b1e-b3ae-bb67ae7e0028@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-04-30 10:21 -0600
Subject Re: mixing set and list operations
Newsgroups comp.lang.python
Message-ID <mailman.131.1430410904.3680.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Apr 30, 2015 at 10:07 AM, Tim <jtim.arnold@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

mixing set and list operations Tim <jtim.arnold@gmail.com> - 2015-04-30 09:07 -0700
  Re: mixing set and list operations Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-30 10:21 -0600
  Re: mixing set and list operations Carl Meyer <carl@oddbird.net> - 2015-04-30 10:16 -0600
  Re: mixing set and list operations Ben Finney <ben+python@benfinney.id.au> - 2015-05-01 03:04 +1000
    Re: mixing set and list operations Tim <jtim.arnold@gmail.com> - 2015-04-30 10:47 -0700

csiph-web