2024-04-24 13:57:14 发布
网友
class Barcode: def __init__(self, code, code_id = None): self.code = code self.id = code_id
我有一份条形码清单。如何获取具有特定id的条形码?在
如果您的BarcodeList没有排序,我建议您使用野蛮的方法:
BarcodeList
def find_item(id): for item in BarcodeList: if item.id == id: return item
如果已排序,请参见What is the best way to get the first item from an iterable matching a condition?
注:为什么不使用dict?它天生就是做这种工作的。在
dict
如果您的
BarcodeList
没有排序,我建议您使用野蛮的方法:如果已排序,请参见What is the best way to get the first item from an iterable matching a condition?
注:为什么不使用
dict
?它天生就是做这种工作的。在相关问题 更多 >
编程相关推荐