Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50981
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!82.197.223.103.MISMATCH!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.053 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; '(so': 0.07; 'method.': 0.07; 'stops': 0.07; 'ascii': 0.09; 'builtin': 0.09; 'iterate': 0.09; "they've": 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"list': 0.16; '3.3,': 0.16; 'dict': 0.16; 'force.': 0.16; 'hypothetical': 0.16; 'mappings,': 0.16; 'objects.': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'obviously': 0.18; 'solution.': 0.20; 'code,': 0.22; 'portion': 0.22; 'cc:addr:python.org': 0.22; "aren't": 0.24; 'entries': 0.24; 'versions': 0.24; 'cc:2**0': 0.24; 'least': 0.26; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'bigger': 0.30; 'characters': 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'too.': 0.31; 'types.': 0.31; 'lists': 0.32; 'are:': 0.33; 'cases': 0.33; 'checking': 0.33; 'there,': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'really': 0.36; 'done': 0.36; 'method': 0.36; 'useful': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'mapping': 0.38; 'pm,': 0.38; 'even': 0.60; 'easy': 0.60; 'dave': 0.60; 'july': 0.63; 'more': 0.64; 'talking': 0.65; 'here': 0.66; 'covers': 0.68; 'gotten': 0.74; 'obvious': 0.74; '100': 0.79; '.replace': 0.84; 'dict.': 0.84; 'faster.': 0.84; 'imagine,': 0.84; 'optimisation': 0.84; 'subject:skip:S 10': 0.84; 'we?': 0.84; 'afford': 0.91; 'angel': 0.91; 'examine': 0.93; 'imagine': 0.93; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=D1fvre15Zw2Y/ht6XL1Ja7z217EF02OaJ9MGDrGPXTQ=; b=oqUDPzXFuhh9+RHDQEdf1MPn4Orb5/qegMgskymVqeX15t7KbCbX6UxNrGHarACfmn au7zwvM3LhrxRaRg6oRaFnzO2oNxVgqHz4a7oaqbhRFJs0ytJfQADpaibPXOvMvZlIYZ V7ZfgaYAgBrAlP7m+RYm1xbdFuQ6Rz3zvqtGXhwuJgPaBI7iUcYpqdcL/SWzsWD1Ge4f tsGGwEjkhRQSHq/JTlmOAj9Olb5pRbn8cDrlj2t/HXsmYrB36sOAGlCRsnS6oSUH24iO BFQ4v40JuvzP8gQod3/gwRVc2idDf3oyAxpYbLJL26WuDsgHYErWL5iEG8PuPgWVhF53 0HjA== |
| X-Received | by 10.152.88.78 with SMTP id be14mr9947884lab.19.1374359644089; Sat, 20 Jul 2013 15:34:04 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | joshua.landau.ws@gmail.com |
| In-Reply-To | <ksf122$d5n$1@ger.gmane.org> |
| References | <mailman.4865.1374240179.3114.python-list@python.org> <51e967bb$0$29971$c3e8da3$5496439d@news.astraweb.com> <ksbt1a$5q1$1@ger.gmane.org> <CAN1F8qXttLWtMFDED-+gEdOR_5tZmDKtqDsF2kdojCRSMAn7eg@mail.gmail.com> <ksdtu7$ctm$1@ger.gmane.org> <CAN1F8qVv0N1D=JEkvWeQePhZg7fT7ULPPXp+ZTOmu=wQCzXiHQ@mail.gmail.com> <ksejfu$ist$1@ger.gmane.org> <CAN1F8qVj2nM6bzLETWm0mmvsrXxQog-qLQF=SRXepEyT4VNCuA@mail.gmail.com> <ksf122$d5n$1@ger.gmane.org> |
| From | Joshua Landau <joshua@landau.ws> |
| Date | Sat, 20 Jul 2013 23:33:23 +0100 |
| X-Google-Sender-Auth | uIaKLPxaiY6qxtL4gJ_c9XEch5I |
| Subject | Re: Find and Replace Simplification |
| To | Dave Angel <davea@davea.name> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4933.1374359653.3114.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1374359653 news.xs4all.nl 15956 [2001:888:2000:d::a6]:52551 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50981 |
Show key headers only | View raw
On 20 July 2013 22:56, Dave Angel <davea@davea.name> wrote:
> On 07/20/2013 02:37 PM, Joshua Landau wrote:
>>
>> The problem can be solved, I'd imagine, for builtin types. Just build
>> an internal representation upon calling .translate that's faster. It's
>> especially easy in the list case
>
> What "list case"? list doesn't have a replace() method or translate()
> method.
I mean some_str.translate(some_list).
>> -- just build a C array¹ at the start
>> mapping int -> int and then have really fast C mapping speeds.
>
>
> As long as you can afford to have a list with a billion or so entries in it.
> We are talking about strings and version 3.3, aren't we? Of course, one
> could always examine the mapping object (table) and see what the max value
> was, and only build a "C array" if it was smaller than say 50,000.
When talking about some_str.translate(some_list), this doesn't apply
very much -- they've already gotten a much bigger Python list.
In the dict case² I don't actually want to jump to the conclusion that
one should do array-based mappings because I can see the obvious
downsides and it's obviously not good to have 100 cases in there,
*but* I still think that there's a solution.
Here are some ideas:
· Latin and ASCII can obviously be done with a C array, and I imagine
that covers at least a fair portion of use-cases.
· If you only have a few characters in the mapping (so sys.getsizeof
is small) then it'll be a lot faster to just iterate through a C list
instead of checking the dict.
· Other cases are:
· Full-character-set or equiv. mappings, which are already faster
than .replace(). Those should really be re-made into lists so that the
list optimisation can take place, and lists are much faster even in
versions without these hypothetical optimizations, too.
· Custom objects. There's nothing we can do here.
I realise that this is a lot more code, so it's not something I'm
going to try to force. However, I think it's useful if it stops people
using .replace in a loop ;).
² some_str.translate(some_dict)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 09:22 -0400
Re: Find and Replace Simplification Novocastrian_Nomad <gregory.j.baker@gmail.com> - 2013-07-19 06:38 -0700
Re: Find and Replace Simplification John Gordon <gordon@panix.com> - 2013-07-19 14:28 +0000
Re: Find and Replace Simplification Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-19 16:22 +0000
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-19 20:29 +0300
Re: Find and Replace Simplification Skip Montanaro <skip@pobox.com> - 2013-07-19 13:08 -0500
Re: Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-19 17:44 -0400
Re: Find and Replace Simplification Dave Angel <davea@davea.name> - 2013-07-19 18:45 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 12:16 +0100
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-20 14:48 +0300
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-20 14:57 +0300
Re: Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 08:41 -0400
Re: Find and Replace Simplification Devyn Collier Johnson <devyncjohnson@gmail.com> - 2013-07-20 08:50 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 18:03 +0100
Re: Find and Replace Simplification Dave Angel <davea@davea.name> - 2013-07-20 14:04 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 19:37 +0100
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 19:41 +0100
Re: Find and Replace Simplification Dave Angel <davea@davea.name> - 2013-07-20 17:56 -0400
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-20 23:33 +0100
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-21 10:44 +0300
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-21 12:29 +0100
Re: Find and Replace Simplification Serhiy Storchaka <storchaka@gmail.com> - 2013-07-21 15:28 +0300
Re: Find and Replace Simplification Joshua Landau <joshua@landau.ws> - 2013-07-21 13:49 +0100
csiph-web