简体   繁体   English

如何检查一个项目是否在二维列表中?

[英]How to check whether an item is in a 2d list or not?

recLst=\[\["10:20","DDSFE","Dyson Digital Slim Fluffy Extra",2599.0,"Iron"\],\["10:25","DV8SF","Dyson V8 Slim Fluffy Plus",1799.0,"Standard"\],\["13:30","DDSFE","Dyson Digital Slim Fluffy Extra",2599.0,"Purple"\],\["13:30","DDSFE","Dyson Digital Slim Fluffy Extra",2599.0,"Iron"\],\["16:15","DV11F","Dyson V11 Fluffy",2899.0,"Red"\],\["17:25","DV8SF","Dyson V8 Slim Fluffy Plus",1799.0,"Standard"\]\]

code ='DDDD'

for i in recLst:
if code not in i\[1\]:
print('No record found')

#Output
No record found
No record found
No record found
No record found
No record found
No record found

The output that i want was the python can go through the list and check whether the code exist or not, if not the system will print out 'No record found' but just for one time.我要的output是python 可以通过list go 看看code是否存在,如果不存在系统会打印'No record found'但是只打印一次。

How to let the system go through the 2 dimensional list and check whether the code is at there or not, if not it will print an output of 'No record found'如何让系统go通过二维表查看是否有code,如果没有则打印output'No record found'

you could try something like this你可以尝试这样的事情

if any([code in i for i in recLst]):
    print("FOUND!")
else:
    print("NOT FOUND")

Good luck:)祝你好运:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM