Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89641
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <carl@oddbird.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'method.': 0.07; 'input,': 0.09; 'method,': 0.09; 'subject:set': 0.09; 'filename:fname piece:signature': 0.16; 'from:addr:carl': 0.16; 'it;': 0.16; 'iterable': 0.16; 'pythonic': 0.16; 'received:173.255': 0.16; 'tim,': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'input': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; 'sets': 0.30; 'subject:list': 0.30; 'work.': 0.31; '>>>>': 0.31; 'object.': 0.31; 'python2.7': 0.31; 'lists': 0.32; 'noticed': 0.34; "i'd": 0.34; 'add': 0.35; 'set.': 0.36; "didn't": 0.36; 'useful': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'today,': 0.61; 'received:173': 0.61; 'received:96': 0.65; 'charset:windows-1252': 0.65 |
| Date | Thu, 30 Apr 2015 10:16:42 -0600 |
| From | Carl Meyer <carl@oddbird.net> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: mixing set and list operations |
| References | <7f1dc7d2-2f88-4b1e-b3ae-bb67ae7e0028@googlegroups.com> |
| In-Reply-To | <7f1dc7d2-2f88-4b1e-b3ae-bb67ae7e0028@googlegroups.com> |
| Content-Type | multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="B8Q7Dq1SAOsaAbdwImtjUpCpjG5d7xp2I" |
| X-Spam-Status | No (score -1.0): ALL_TRUSTED=-1 |
| X-Spam-Bar | - |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.132.1430412418.3680.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430412418 news.xs4all.nl 2916 [2001:888:2000:d::a6]:33433 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89641 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi Tim, On 04/30/2015 10:07 AM, Tim 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. > >>>> m = ['one', 'two'] >>>> p = set(['three', 'four']) >>>> m.extend(p) >>>> m > ['one', 'two', 'four', 'three'] > >>>> m = ['one', 'two'] >>>> p = set(['three', 'four']) >>>> p.update(m) >>>> p > set(['four', 'three', 'two', 'one']) > > > Useful if you don't care about ordering. Not sure if it's dangerous. I don't think this is surprising, nor implementation dependent, nor dangerous. Lists have an `extend()` method, sets have an `update()` method. Both of these methods take any iterable as input, they don't needlessly constrain the input to be of the same type as the base object. That's the Pythonic way to do it; I'd be surprised if it didn't work. Carl
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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