Hello everyone. I’ve got pretty basic python code that should work but it doesn’t.
def filter_by_value(coins, value): return [item for item in coins if item.value == value] loop: items = self.findItems() for val in [3, 2, 1]: filtered = filter_by_value(items, val) if filtered: nearest = self.findNearest(filtered) self.moveXY(nearest.pos.x, nearest.pos.y) break
My intention is to collect nearest gold coin if it exists otherwise collect nearest silver coin if it exists otherwise - the same for copper.
Considering errors, it seems that branch
if filtered: is executed even if
filtered is an empty list.
Developers, any ideas what construction could drive the code parser crazy?
I’ve read lots of similar topics, but there were no solutions that would fit. Thank you.