我有一个数组,如下所示。我想将用户响应与此数组进行比较。
array = ['finance', 'healthcare', 'information technology', 'government', 'textile', 'petroleum']
这是我的密码。
if str(user_response) in str(array):
for j in range(array_length):
if str(user_response) == str(array[j]):
some code
else:
print("give valid answer")
如果用户的反应是
“信息技术”
,那么它工作得很好。但如果用户的反应是
技术
然后,它也被认为是一个答案。它必须打印
else
用户将给出如下响应时的消息
技术
.
那么,我如何从数组中匹配整个单词“信息技术”,而不是仅匹配“技术”?