如何解决值错误:不在列表中

我在这里遇到了同样的问题,而它实际上在列表中。可能这里还有另一个错误是我的代码检查它,请:

base = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
c= base.index(a)

a是输入,我确保它是“o”,“k”

ValueError: ['o', 'k'] is not in list

另外,我不能放,因为必须完成这行,否则整个程序不起作用try:


青春有我
浏览 155回答 2
2回答

烙印99

您可以尝试给定输入中的每个字母,如下所示,输入:ip = ["o", "k"]c = (base.index(i) for i in ip)输出:for i in c:...     print(i)...1410

白衣非少年

Base 似乎不是列表的列表。而不是:if ['o','k'] in list:您应该使用:if 'o' in list and 'k' in list:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python