Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38809
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rantingrickjohnson@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.006 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:skip:s 10': 0.05; 'arguments': 0.07; '[1]:': 0.09; 'dict': 0.09; 'to:addr:comp.lang.python': 0.09; 'tuple': 0.09; 'cc:addr:python- list': 0.10; 'passing': 0.15; "skip:' 30": 0.15; "'b',": 0.16; 'examples:': 0.16; 'hypothetical': 0.16; 'op.': 0.16; 'references:': 0.16; 'sequence:': 0.16; 'string': 0.17; 'wrote:': 0.17; 'cc:2**0': 0.23; 'example': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'fine': 0.28; "skip:' 10": 0.30; 'function': 0.30; 'johnson': 0.32; "skip:' 20": 0.32; '"")': 0.33; 'null': 0.33; 'handle': 0.33; 'received:google.com': 0.34; 'or,': 0.34; 'basis.': 0.35; 'sequence': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; '12,': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'apply': 0.39; 'list,': 0.39; 'where': 0.40; 'your': 0.60; 'here': 0.65; '2013': 0.84; 'again!': 0.84; 'rick': 0.91; 'time)': 0.91; 'mistakes': 0.95 |
| X-Received | by 10.49.35.77 with SMTP id f13mr1356742qej.4.1360733197736; Tue, 12 Feb 2013 21:26:37 -0800 (PST) |
| Newsgroups | comp.lang.python |
| Date | Tue, 12 Feb 2013 21:26:37 -0800 (PST) |
| In-Reply-To | <92122dd3-ac2e-4407-87ed-0b250ed9c8b9@googlegroups.com> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=70.196.64.56; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj |
| References | <mailman.1536.1360407866.2939.python-list@python.org> <92122dd3-ac2e-4407-87ed-0b250ed9c8b9@googlegroups.com> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 70.196.64.56 |
| MIME-Version | 1.0 |
| Subject | Re: string.replace doesn't removes ":" |
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Cc | 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> |
| Message-ID | <mailman.1738.1360733201.2939.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360733201 news.xs4all.nl 6928 [2001:888:2000:d::a6]:52320 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38809 |
Show key headers only | View raw
On Tuesday, February 12, 2013 10:44:09 PM UTC-6, Rick Johnson wrote:
> ============================================================
> REFERENCES:
> ============================================================
> [1]: Should string.replace handle list, tuple and dict
> arguments in addition to strings?
>
> py> string.replace(('a', 'b', 'c'), 'abcdefgabc')
> 'defg'
> [...]
And here is a fine example of how a "global function architecture" can seriously warp your mind! Let me try that again!
Hypothetical Examples:
py> 'abcdefgabc'.replace(('a', 'b', 'c'), "")
'defg'
py> 'abcdefgabc'.replace(['a', 'b', 'c'], "")
'defg'
py> 'abcdefgabc'.replace({'a':'A', 'b':'2', 'c':'C'})
'A2CdefgA2C'
Or, an alternative to passing dict where both old and new arguments accept the sequence:
py> d = {'a':'A', 'b':'2', 'c':'C'}
py> 'abcdefgabc'.replace(d.keys(), d.values())
'A2CdefgA2C'
Nice thing about dict is you can control both sub-string and replacement-string on a case-by-case basis. But there is going to be a need to apply a single replacement string to a sequence of substrings; like the null string example provided by the OP.
(hopefully there's no mistakes this time)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
string.replace doesn't removes ":" Joshua Robinson <shooki.robinson@gmail.com> - 2013-02-09 06:04 -0500
Re: string.replace doesn't removes ":" Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-02-10 11:36 +0100
Re: string.replace doesn't removes ":" vduncan80@gmail.com - 2013-02-12 07:14 -0800
Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 20:44 -0800
Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 21:26 -0800
Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 21:26 -0800
Re: string.replace doesn't removes ":" jmfauth <wxjmfauth@gmail.com> - 2013-02-12 23:10 -0800
Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-13 08:34 -0800
Re: string.replace doesn't removes ":" Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-13 16:55 +0000
Re: string.replace doesn't removes ":" Walter Hurry <walterhurry@lavabit.com> - 2013-02-13 18:16 +0000
Re: string.replace doesn't removes ":" 88888 Dihedral <dihedral88888@googlemail.com> - 2013-02-13 12:24 -0800
Re: string.replace doesn't removes ":" jmfauth <wxjmfauth@gmail.com> - 2013-02-14 00:02 -0800
Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 20:44 -0800
csiph-web