An example: you want to collect unique asset numbers from multiassetlocci.
Common approach using list of asset numbers:
assetnums = []
for row in multiassetset:
asset = row.getString("ASSETNUM")
if asset and asset not in assetnums:
assetnums.append(asset)
Functionally fine. Until you run it on a record with 2000 assets and would be surprised how slow it is...
It would be better and faster if you would use set and not list:
assetnums = set()
for row in multiassetset:
asset = row.getString("ASSETNUM")
if asset:
assetnums.add(asset)
When using set you wouldn't have duplicates and you would have constant lookup time.
Just remember:
- Use set() when you only need unique values or fast membership checks.
- Use list() when order or index access matters.
Ever noticed the difference yourself? Or do you have a script that felt just a bit too slow for no reason?
I would be happy to assist: info@annacode.nl

Anna van den Akker
Experienced IBM Maximo consultant with a solid software engineering background. I help businesses improve their systems effectively, handling tough tasks and delivering great outcomes.Category
Tags