python - 我正在编写一个基本的 python 程序来检查字符串是否出现在字符串列表中
问题描述
如何检查python列表中是否存在字符串?
with open('pwds.csv', newline='\n') as csvfile:
global passwordlist
passwords = csv.reader(csvfile,delimiter=',')
passwordlist = []
for row in passwords:
global passwordlist
passwordlist = list(passwords)
map(lambda passwordlist: str.replace ("['", ""), passwordlist)
print (passwordlist)
我正在尝试将数据存储在 CSV 文件中,然后在 python 中读取它以查看它是否包含用户输入中给出的字符串。目前,即使我让程序打印列表以确保字符串确实存在,程序也总是无法在列表中找到输入的字符串。我只是迷路了。这是一项针对扩展工作的 GCSE 计算挑战任务。
解决方案
mylist = ["a", "b", "c"]
if a in mylist:
#do something if "a" is in the list
如果列表真的很大:
mylist = ["a", "b", "c"]
myset = set(mylist)
if a in mylist:
#do something if "a" is in the list
推荐阅读
- c# - ExecuteNonQuery 指向一个较旧的、不存在的数据库
- single-sign-on - Keycloak 问题和从 SAML 身份提供者注销
- microsoft-graph-api - 根据 singleValueExtendedProperty 的特定值搜索事件
- google-cloud-storage - Google pubsub 侦听器未收到所有消息
- java - 如何解决 java.lang.ClassNotFoundException: org.aspectj.lang.ProceedingJoinPoint 异常?
- css - 重用组件时,我的 CSS 没有应用到它
- css - 找不到角度资产静态文件
- javascript - 再次出现错误“SyntaxError”,但现在我按照我过去问题的答案
- python-3.x - 如何访问存储在 Google Cloud Storage 中的 jpeg 文件?
- keras - 图像回归:正方形的宽度