如何将列表转换为ASCII

2024-03-28 11:32:29 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将列表转换成ASCII格式,但我想在转换后重新生成一个列表。在

我在从ASCII转换为列表时发现了这个:

L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
print(''.join(map(chr,L)))

但它不能反过来工作。在

这是我的输入:

^{pr2}$

我想要这个作为输出:

L = ['104','101','108','108','111']

Tags: map列表格式asciiprintjoinchrpr2
3条回答

这是一个更简单的解决方案:

L = ['h','e','l','l','o']
changer = [ord(x) for x in L]
print(changer)

使用函数ord()

L = ['h','e','l','l','o']
print(list(map(str, map(ord, L))))

该输出:

^{pr2}$

这对我很有效。在

>>> L = [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
>>> print [ chr(x) for x in L]
['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd']

相关问题 更多 >