[Tim' >> ... >> There are few enough bugs in my code at this age that I take very >> seriously any principled gimmick that could prevent repeating one. [Raymond] > Alex Martelli had proposed extending the key= idea to min() and max(). > The idea is to let those functions completely encapsulate the logic > of searching for minimum and maximum elements: > > bestplayer = min(players, key=attrgetter('points')) > > This would work equally well with other objective functions. Different issue. I didn't have "a sequence". The loop was more like: global_minimum = made_up_value_presumed_to_be_unreachably_large while mote_to_look_at: do a ton of computation, yielding a candidate if score(candidate) < global_minimum: global_minimum = score(candidate) do a ton of stuff to prune the search based on the new (so far) local minimum return global_minimum It's picking the made_up_value_presumed_to_be_unreachably_large that's a brittle hack, and is specifically the source of the bug I mentioned. Adding new twists to min() wouldn't have made any difference to that.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4