If your BarcodeList
isn’t sorted, I recommend the brutal approach:
def find_item(id):
for item in BarcodeList:
if item.id == id:
return item
If it is sorted, see What is the best way to get the first item from an iterable matching a condition?
PS: Why not use dict
? It’s born for doing this sort of job.
3
solved How to get a specific item from python list [duplicate]