2013-06-10 15 views

उत्तर

52

इस्तेमाल किया कुंजी पात्रों में से ऑर्डिनल्स, नहीं वर्ण खुद को कर रहे हैं:

'a'.translate({ord('a'): 'b'}) 

यह होने के लिए str.maketrans

>>> 'a'.translate(str.maketrans('a', 'b')) 
'b' 

>>> help(str.translate) 
Help on method_descriptor: 

translate(...) 
    S.translate(table) -> str 

    Return a copy of the string S, where all characters have been mapped 
    through the given translation table, which must be a mapping of 
    Unicode ordinals to Unicode ordinals, strings, or None. 
    Unmapped characters are left untouched. Characters mapped to None 
    are deleted. 
+2

केवल कुंजी जरूरतों उपयोग करना आसान हो एक ordinal (http://docs.python.org/3/library/stdtypes.html#str.translate) – Volatility

+0

त्वरित उत्तर के लिए धन्यवाद, मैं जल्द ही स्वीकार करूंगा। – fhucho

+0

:(क्या मुझे याद आया जब जैमिलैक ने निर्माता को पोस्ट किया? – TerryA

संबंधित मुद्दे