string.replace doesn't removes ":"

Rick Johnson rantingrickjohnson at gmail.com
Wed Feb 13 11:34:11 EST 2013


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€€€€€€€€€€€€€'

[quip] I just really prefer a cryptic solution to a problem when a simplistic and consistent approach would suffice.[/quip] TO HELL WITH THE ZEN!

"Beautiful is better than ugly."
  BROKEN!

"Explicit is better than implicit."
  BROKEN!

"Simple is better than complex."
  BROKEN!

"Sparse is better than dense."
  BROKEN!

"Readability counts."
  BROKEN BROKEN BROKEN!!!!

"Special cases aren't special enough to break the rules."
  BROKEN!

"In the face of ambiguity, refuse the temptation to guess."
  BROKEN!

"There should be one-- and preferably only one --obvious way to do it."
  BROKEN BROKEN BROKEN!

"If the implementation is hard to explain, it's a bad idea."
  BROKEN!

"If the implementation is easy to explain, it may be a good idea."
  REINFORCED BY BAD EXAMPLE



More information about the Python-list mailing list