Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38809

Re: string.replace doesn't removes ":"

Newsgroups comp.lang.python
Date 2013-02-12 21:26 -0800
References <mailman.1536.1360407866.2939.python-list@python.org> <92122dd3-ac2e-4407-87ed-0b250ed9c8b9@googlegroups.com>
Subject Re: string.replace doesn't removes ":"
From Rick Johnson <rantingrickjohnson@gmail.com>
Message-ID <mailman.1738.1360733201.2939.python-list@python.org> (permalink)

Show all headers | 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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