tracking some ideas
Author: kurtbroseCreated Aug 24, 2023Updated Oct 8, 2024
These need gardening but I'll just put them here to keep track.
def get_any(dict, *keys, default=None):
"""Cascading get, for those times you do `dict.get(key1, dict.get(key2, ...))"""
for key in keys:
if key in dict:
return dict[key]
return defaultBut I had another take on get_any() here, so need to resolve that.
https://github.com/mahmoud/boltons/issues/266
Another one is a multi-partition, where predicates cascade:
future, current, past = partition(items, lambda item: item.start > now, lambda item: item.end > now)(this could be an extension of iterutils.partition to accept any number of predicates instead of just one)
Source: mahmoud/boltons