Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100178
| Path | csiph.com!au2pb.net!2.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: filter a list of strings |
| Date | Tue, 08 Dec 2015 23:58:42 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 31 |
| Message-ID | <2598115.t018ozAsXX@PointedEars.de> (permalink) |
| References | <3p9zlt5t5Vz5vN5@dovecot03.posteo.de> <mailman.171.1449145727.14615.python-list@python.org> |
| Reply-To | Thomas 'PointedEars' Lahn <usenet@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1449615523 27089 eJwNyMEBwEAEBMCWYo9FOUj0X8JlnmOHwnGlUW1tc2RZgfy/ergows6MpqM/8Wax643Gkwi7HOYRAA== (8 Dec 2015 22:58:43 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Tue, 8 Dec 2015 22:58:43 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNx8EBwCAIA8CVgBiQcZQ2+4/Q3u+I9JxayVwUJWzDEyZYtlPPnIu5b/+FQ3ViKLcLrLhkeGVNm3ZsRM8HQowUmA== |
| Cancel-Lock | sha1:q9STYhFtqAD280LlBeXIzXShBfE= |
| X-NNTP-Posting-Host | eJwFwYEBgDAIA7CXcKMFzhEq/59ggsuHE07QsVh+ytXRqFsxFsx4WSZzF1Cnb5eOp4xU5w8z0xFw |
| Xref | csiph.com comp.lang.python:100178 |
Show key headers only | View raw
Mark Lawrence wrote: > On 03/12/2015 01:15, c.buhtz@posteo.jp wrote: >> I would like to know how this could be done more elegant/pythonic. >> >> I have a big list (over 10.000 items) with strings (each 100 to 300 >> chars long) and want to filter them. >> >> list = ..... >> […] > > targets = ['Banana', 'Car'...] > for item in list[:]: > for target in targets: > if target in item: > list.remove(item) > >> btw: Is it correct to iterate over a copy (list[:]) of that string list >> and not the original one? > > Absolutely :) However, “list” is a built-in class/constructor that would be overwritten this way. One should choose another identifier than “list” for one’s variables. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: filter a list of strings Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-03 12:28 +0000
Re: filter a list of strings Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-12-08 23:58 +0100
Shadowing built-ins [was Re: filter a list of strings] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-12-09 18:38 +1100
Re: filter a list of strings Sivan Greenberg <sivan@vitakka.co> - 2015-12-09 16:35 +0200
csiph-web