这是我的代码:
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/