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: 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: <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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: 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 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)