python - 为什么我的代码不打印整个列表?

标签 python

这是我的代码:

import string
l=string.ascii_lowercase

the_input=list(raw_input("Enter your message to encode it: "))
for i in the_input:
    xyz=[l.find(i)+1] 
#set_alpha_num=[alphabets.index(find) for find in user_msg] 
print(xyz)

如果我输入 "test" 那么它只打印 [20] 但我需要输出应该是这样的:[20, 5, 19, 20 ]

最佳答案

这按照您的要求工作:

import string
l=string.ascii_lowercase
xyz=[]
the_input=list(raw_input("Enter your message to encode it: "))
for i in the_input:
    xyz +=[l.find(i)+1]
#set_alpha_num=[alphabets.index(find) for find in user_msg]
print(xyz)

关于python - 为什么我的代码不打印整个列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50391725/

相关文章:

python - NumPy 2D 数组普通切片与基于 bool 的切片

python - Matplotlib - 等高线图

python - 使用 ID 创建对象并填充其他字段

python - 如何在python中正确打开文件并打印出文本内容

python - 检查两个列表一致性的快速方法

python - Nexus 存储库管理器作为 pip 本地服务器无法正常工作

Python 填充列表的快捷方式

Python矩阵添加对角线元素

python - 如何在 Python 中使用 Selenium 从具有 "display: none"属性的 Web 元素中选择任何元素

python - 将二进制字符串转换为十六进制字符串并保留其前导零