Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89644
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:set': 0.09; 'accepts': 0.16; 'collections': 0.16; 'finney': 0.16; 'iterable': 0.16; 'marie': 0.16; 'merely': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'elements': 0.16; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'url:moin': 0.24; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'tim': 0.29; 'sets': 0.30; 'subject:list': 0.30; 'url:wiki': 0.31; 'writes:': 0.31; 'lists': 0.32; 'url:python': 0.33; 'add': 0.35; 'version': 0.36; 'set.': 0.36; 'url:org': 0.36; 'list': 0.37; 'ben': 0.38; 'to:addr :python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'dangerous': 0.60; 'skip:\xe2 10': 0.65; 'discovered': 0.83; 'received:125': 0.84; '\xe2\x80\xa6': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ben Finney <ben+python@benfinney.id.au> |
| Subject | Re: mixing set and list operations |
| Date | Fri, 01 May 2015 03:04:30 +1000 |
| References | <7f1dc7d2-2f88-4b1e-b3ae-bb67ae7e0028@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| Cancel-Lock | sha1:MsWnraUSe9/jVAU9C+Yugh0creE= |
| 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.134.1430413495.3680.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430413495 news.xs4all.nl 2963 [2001:888:2000:d::a6]:41898 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Bytes | 3830 |
| X-Received-Body-CRC | 3555319147 |
| Xref | csiph.com comp.lang.python:89644 |
Show key headers only | View raw
Tim <jtim.arnold@gmail.com> writes:
> You can use 'extend' to add set elements to a list and use 'update' to
> add list elements to a set.
And you can use both of those methods to add items from a file::
>>> foo = ['one', 'two']
>>> bar = open('/usr/share/common-licenses/GPL-3')
>>> foo.extend(bar)
>>> foo
['one', 'two', ' GNU GENERAL PUBLIC LICENSE\n',
' Version 3, 29 June 2007\n', '\n',
…
You have merely discovered that ‘list.extend’ and ‘set.update’ accept an
iterable <URL:https://wiki.python.org/moin/Iterator>.
Sets and lists and files and many other collections are all iterables,
so any of them can be passed to a function that accepts an iterable.
--
\ “It's dangerous to be right when the government is wrong.” |
`\ —Francois Marie Arouet Voltaire |
_o__) |
Ben Finney
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