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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to