diff Lib/stringold.py @ 3639:70183592370e legacy-trunk

add translate() -- which was in strop per release 1.3
author Guido van Rossum <guido@python.org>
date Tue, 28 May 1996 23:08:45 +0000
parents 4f9d4e73057c
children 1d134ecda094
line wrap: on
line diff
--- a/Lib/stringold.py	Tue May 28 23:08:25 1996 +0000
+++ b/Lib/stringold.py	Tue May 28 23:08:45 1996 +0000
@@ -253,6 +253,14 @@
 			line = ''
 	return res + line
 
+# Character translation through look-up table.
+def translate(s, table):
+    if type(table) != type('') or len(table) != 256:
+	raise TypeError, "translation table must be 256-char string"
+    res = ""
+    for c in s:
+	res = res + table[ord(c)]
+    return res
 
 # Try importing optional built-in module "strop" -- if it exists,
 # it redefines some string operations that are 100-1000 times faster.