-
maketrans translate
-
- intab = "abcd"
- outtab = "1234"
- str_trantab = str.maketrans(intab,outtab)
-
- test_str = "csdn blog: http://blog.csdn.net/wirelessqa"
-
- print (test_str.translate(str_trantab))
-
-
-
-
- print(b'http://www.csdn.net/wirelessqa'.translate(None, b'ts'))
-
- bytes_tabtrans = bytes.maketrans(b'abcdefghijklmnopqrstuvwxyz', b'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
- print(b'http://www.csdn.net/wirelessqa'.translate(bytes_tabtrans, b'ts'))
-
-
- def make_adder(addend):
- def adder(augend):
- return augend + addend
- return adder
-
- a = make_adder(1)
- b = make_adder(2)
- print (a(100), b(100))
-
- def my_translator(frm = b'', to = b'', delete = b'', keep = None):
-
- if len(to) == 1:
- to = to * len(frm)
-
-
- trans = bytes.maketrans(frm, to)
-
- if keep is not None:
- allchars = bytes.maketrans(b'', b'')
- keep = keep.translate(allchars, delete)
- delete = allchars.translate(allchars, keep)
-
-
-
- def my_translate(s):
- return s.translate(trans, delete)
-
- return my_translate
-
-
-
- digits_only = my_translator(keep = b'0123456789')
- print(digits_only(b'http://www.csdn.net/wirelessqa 520520'))
-
- no_digits = my_translator(delete = b'0123456789')
- print(no_digits(b'http://www.csdn.net/wirelessqa 520520'))
-
- digits_to_hash = my_translator(frm = b'0123456789', to = b'*')
- print(digits_to_hash(b'http://www.csdn.net/wirelessqa 520520'))
-
- trans = my_translator(delete = b'20', keep = b'0123456789')
- print(trans(b'http://www.csdn.net/wirelessqa 520520'))
-
相关阅读:
PHP之数据库操作(一)
PHP之字符串操作
Subline使用方法
POST和GET的区别(面试回答)
面试题(1)
http协议
JS 闭包(内存溢出与内存泄漏)(垃圾回收机制)
JS----事件机制 事件冒泡 事件捕获 事件委托
js的数据类型、判断对象类型 js对象
JS----DOM节点操作:创建 ,插入,删除,复制,查找节点
-
原文地址:https://www.cnblogs.com/yingqml/p/6178802.html
Copyright © 2020-2023
润新知