Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
得到一个 ASCII 字符串(只有 AZ、az 和 "" 的 ASCII 值范围),想要对其进行解码。
前任。“781059910132”对应“Nice”
在 Python 3 中是否有一种简单的方法可以做到这一点?
您可以使用正则表达式来提取 3 位或 2 位数字组合:
import re ascii_char = '[01]?\d\d' s = '781059910132' ''.join(map(chr, map(int, re.findall(ascii_char, s)))) #'Nice '
此代码甚至可以使用 0 填充代码:
''.join(map(chr, map(int, re.findall(ascii_char, '07832078')))) #'N N'