我想将从 bin
给出的内容转换为列表。
我有:
x = input()
for y in x:
z = (bin(ord(y)))
print (z)
我得到了什么:
0b1101000
0b1100101
0b1101100
0b1101100
0b1101111
我想要什么:
[0b1101000, 0b1100101, 0b1101100, 0b1101100, 0b1101111]
最佳答案
使用 list comprehension :
z = [bin(ord(y)) for y in x]
print(z)
这是一个快捷方式:
z = []
for y in x:
z.append(bin(ord(y))]
print(z)
关于python - 将列表从 ord 转换为 List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36346305/