Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38853
| X-Received | by 10.224.208.9 with SMTP id ga9mr310833qab.8.1360828930927; Thu, 14 Feb 2013 00:02:10 -0800 (PST) |
|---|---|
| MIME-Version | 1.0 |
| X-Received | by 10.49.60.40 with SMTP id e8mr1520810qer.40.1360828930906; Thu, 14 Feb 2013 00:02:10 -0800 (PST) |
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!p13no525833qai.0!news-out.google.com!k2ni32873qap.0!nntp.google.com!p13no16062461qai.0!postnews.google.com!h9g2000vbk.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Thu, 14 Feb 2013 00:02:10 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | h9g2000vbk.googlegroups.com; posting-host=178.198.163.217; posting-account=ung4FAoAAAC46zhHJ0Nsnuox7M5gDvs_ |
| NNTP-Posting-Host | 178.198.163.217 |
| References | <mailman.1536.1360407866.2939.python-list@python.org> <92122dd3-ac2e-4407-87ed-0b250ed9c8b9@googlegroups.com> <mailman.1738.1360733201.2939.python-list@python.org> <25d2297a-6fee-4ef5-bcbd-e26a28cf6ce4@e10g2000vbv.googlegroups.com> <fbca1681-2814-4331-91c1-cce852ce530d@googlegroups.com> <4ca31c17-1ec6-43dc-806f-5ef7925334b9@googlegroups.com> |
| User-Agent | G2/1.0 |
| X-HTTP-UserAgent | Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0,gzip(gfe) |
| Message-ID | <8a53eab7-e0aa-4488-920e-2b7080949497@h9g2000vbk.googlegroups.com> (permalink) |
| Subject | Re: string.replace doesn't removes ":" |
| From | jmfauth <wxjmfauth@gmail.com> |
| Injection-Date | Thu, 14 Feb 2013 08:02:10 +0000 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Received-Bytes | 3574 |
| Xref | csiph.com comp.lang.python:38853 |
Show key headers only | View raw
On 13 fév, 21:24, 88888 Dihedral <dihedral88...@googlemail.com> wrote:
> Rick Johnson於 2013年2月14日星期四UTC+8上午12時34分11秒寫道:
>
>
>
>
>
>
>
> > On Wednesday, February 13, 2013 1:10:14 AM UTC-6, jmfauth wrote:
>
> > > >>> d = {ord('a'): 'A', ord('b'): '2', ord('c'): 'C'}
>
> > > >>> 'abcdefgabc'.translate(d)
>
> > > 'A2CdefgA2C'
>
> > > >>> def jmTranslate(s, table):
>
> > > ... table = {ord(k):table[k] for k in table}
>
> > > ... return s.translate(table)
>
> > > ...
>
> > > >>> d = {'a': 'A', 'b': '2', 'c': 'C'}
>
> > > >>> jmTranslate('abcdefgabc', d)
>
> > > 'A2CdefgA2C'
>
> > > >>> d = {'a': None, 'b': None, 'c': None}
>
> > > >>> jmTranslate('abcdefgabc', d)
>
> > > 'defg'
>
> > > >>> d = {'a': '€€€€€', 'b': '€€€€', 'c': '€€€€'}
>
> > > >>> jmTranslate('abcdefgabc', d)
>
> > > '€€€€€€€€€€€€€defg€€€€€€€€€€€€€'
>
> In python the variables of value types, and the variables of lists and
> dictionaries are passed to functions somewhat different.
>
> This should be noticed by any serious programmer in python.
---------
The purpose of my quick and dirty fct was to
show it's possible to create a text replacement
fct which is using exclusively text / strings
via a dict. (Even if in my exemple, I'm using
- and can use - None as an empty string !)
You are right.
It is also arguable, that beeing forced to have
to use a number in order to replace a character,
may not be a so good idea.
This should be noticed by any serious language designer.
More seriously.
.translate() is a very nice and underestimated method.
jmf
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