gpt4 book ai didi

python - 如何检查输入的字母是否在列表中?

转载 作者:太空宇宙 更新时间:2023-11-04 07:18:58 24 4
gpt4 key购买 nike

如何检查用户输入的单词的字母是否都在列表中?这似乎不起作用:

letters = ["a","b","c","d"]
inpt = str(raw_input())
if list(inpt) in letters:
print "letters are in list"
else:
print "letters are not in list"

最佳答案

比如像这样?

letters = set(["a","b","c","d"])
inpt = raw_input()
if set(inpt).issubset(letters):
print "letters are in list"
else:
print "letters are not in list"

比照。 Python - verifying if one list is a subset of the other

关于python - 如何检查输入的字母是否在列表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28237231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com